10
print_r($arraydata);

I got output

Array ( [0] => vikas [1] => shirt [2] => cloth1 [3] => test [4] => shirt [5] => cloth2 [6] => avi )

i need to show array like that

$arr = array("vikas","shirt","cloth1","test","shirt","cloth2","avi");

2
  • 2
    Similar topic here Commented Jul 18, 2012 at 20:28
  • 2
    echo implode($arraydata, ','); Commented Jul 18, 2012 at 20:28

2 Answers 2

16

Use this :

echo '$arr = array("'.implode('", "', $arraydata).'");';
Sign up to request clarification or add additional context in comments.

1 Comment

For those that like single quotes and not double quotes, and the new [] vs array(), here ya go: echo "[" . implode("', '", $array) . "]";
0

If comma separation is necessary:

echo '$arr = array(';
foreach ($array as $key => $value) {
  if ($key > 0) echo ',';
  echo '"'.$value.'"';
}
echo ');';

2 Comments

@Mike That's very true, and Vincents answer above is better :)
not when you have 1.5 million rows and is close to get an out-of-memory crash, it isn't!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.