Take the 2-minute tour ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

This question already has an answer here:

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 );
share|improve this question

marked as duplicate by nemo, Glavić, Maks3w, ChrisForrence, Sergiu Paraschiv Apr 23 '14 at 9:07

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

2  
what language is this? add it as a tag. –  Armen B. Sep 20 '13 at 18:06
    
sorry, it is PHP –  Stephen Sep 20 '13 at 18:07
    
you are using var_dump. can you give $array –  Nitish Kumar Sep 20 '13 at 18:09
    
nemo: it DOES seem to be a dupe, thanks! That solved my problem. –  Stephen Sep 20 '13 at 18:22
    
It should work, probably you have made any mistake or post the array that you are var_dumping. –  The Alpha Sep 20 '13 at 18:23

1 Answer 1

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);
share|improve this answer
    
The string in your answer is the result of var_dump($array) and not a json string. –  The Alpha Sep 20 '13 at 18:21
    
Check this. –  The Alpha Sep 20 '13 at 18:27

Not the answer you're looking for? Browse other questions tagged or ask your own question.