Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to implode the following array for $val = explode(",".$number)

Array
(
    [0] => Array
    (
        [num] => 338975270
    )
    [1] => Array
    (
        [num] => 4542682328
    )
)

now i want to use implode function to get output like :

(338975270,4542682328)
like image 893
Uma Avatar asked Oct 01 '22 23:10

Uma


2 Answers

You should ..

echo "(".implode(',', array_map(function ($v){ return $v['num'];},$yourarray)).")";

Working Demo

Explanation :

You can't directly use implode() on a MD array. So use an array_map() to grab all those values with num key and then subject that to your implode().

like image 165
Shankar Narayana Damodaran Avatar answered Oct 13 '22 09:10

Shankar Narayana Damodaran


This should solve your problem

$result = implode(',',array_column($a,'num')));

Extract values and implode them

like image 31
mleko Avatar answered Oct 13 '22 11:10

mleko