1

i have following array, and i have tried to add comma with the following code but i am not getting values its shows "array" only..

Array Value

Array (
[0] => Array ( 
   [0] => 144 [category_id] => 144 ) 
   [1] => Array ( [0] => 98 [category_id] => 98 ) 
   [2] => Array ( [0] => 146 [category_id] => 146 ) 
   [3] => Array ( [0] => 142 [category_id] => 142 )
)

Tried code to display values with commas

$comma_separated = implode(",", $result_array);
echo $comma_separated;

output i am getting

Array,Array,Array,Array

please check what i am getting wrong

1
  • 144,98,146,142.....got the answer thanks Commented Aug 22, 2012 at 23:56

1 Answer 1

1
$comma_separated = implode(',', array_map(function($i) { return $i[0]; }, $result_array));
echo $comma_separated;
Sign up to request clarification or add additional context in comments.

Comments

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.