Array ( [0] => 1,2,1,23,5,2 [1] => 1,1,1,2,3,2 [2] => 2,3,4,2 )
So I have this array. I want the all data in a single array like this.How to achieve this.
Array ( [0] => 1,2,1,23,5,2,1,1,1,2,3,2,2,3,4,2)
Array ( [0] => 1,2,1,23,5,2 [1] => 1,1,1,2,3,2 [2] => 2,3,4,2 )
So I have this array. I want the all data in a single array like this.How to achieve this.
Array ( [0] => 1,2,1,23,5,2,1,1,1,2,3,2,2,3,4,2)
Merge array in Codeigniter and PHP
$multiArr = Array ( 0 => Array (1,2,1,23,5,2),
1 => Array (1,1,1,2,3,2),
2 => Array (2,3,4,2)
);
//-method merge 1-//
foreach($multiArr as $val)
{
foreach($val as $val2)
{
$result[]=$val2;
}
}
//-method merge 2-//
//$result = array_merge($multiArr[0], $multiArr[1], $multiArr[2]);
foreach($result as $val)
{
echo $val.", ";
}
result: 1, 2, 1, 23, 5, 2, 1, 1, 1, 2, 3, 2, 2, 3, 4, 2,
It seems to me that you just want to implode the comma-delimited 0 column values with the same delimiter.
Code: (Demo)
$array = [
['1,2,1,23,5,2'],
['1,1,1,2,3,2'],
['2,3,4,2'],
];
$result[0] = implode(',', array_column($array, 0));
var_export($result);
Output:
array (
0 => '1,2,1,23,5,2,1,1,1,2,3,2,2,3,4,2',
)
If you'd rather simplify the result structure to a basic string, remove the [0] when making the $result assignment.
If you'd rather have separate values, just explode(',', $result[0])