0

I am sure this is something simple, but I can't find it anywhere:

How can I change an array like this:

{ [0]=> string(3) "674" [1]=> string(3) "675" [2]=> string(3) "676" [3]=> string(3) "677" } 

into a simple one like this:

(674,675,676,677)

For use in another SQL (IN) query?

I have tried imploding and it fails.

$myarray_value = implode( ',', $myarray );
6
  • 2
    what language is this? add it as a tag. Commented Sep 20, 2013 at 18:06
  • you are using var_dump. can you give $array Commented Sep 20, 2013 at 18:09
  • nemo: it DOES seem to be a dupe, thanks! That solved my problem. Commented Sep 20, 2013 at 18:22
  • It should work, probably you have made any mistake or post the array that you are var_dumping. Commented Sep 20, 2013 at 18:23
  • Check this, should work. Commented Sep 20, 2013 at 18:27

1 Answer 1

2

What you are looking at is in JSON format, so just do this:

$string = '{ [0]=> string(3) "674" [1]=> string(3) "675" [2]=> string(3) "676" [3]=> string(3) "677" }';
$array = json_decode($string);
print_r($array);
2
  • The string in your answer is the result of var_dump($array) and not a json string. Commented Sep 20, 2013 at 18:21
  • Check this. Commented Sep 20, 2013 at 18:27

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.