PHP - array merge - remove array keys from array before merging
Below is the result of the print_r($result)
variable $result = array_merge(array($id => $value), array($user => $value), array("Information" => $value))
in the PHP code snippet:
Array ( [id] => 1 [user] => 1
[Information] => Array ( [0] => Array ( [name] => 'John' )
[1] => Array ( [family] => 'Goldenberg' )
[2] => Array ( [age] => '21' )))
How to remove array keys from array "Information" => $value
in PHP to make output as below:
Array ( [id] => 1 [user] => 1
[Information] => Array ([name] => 'John'
[family] => 'Goldenberg'
[age] => '21'))
Is there some specific function in PHP to accomplish this task? Many thanks for your help.
+3
source to share
1 answer
Your Information array is multidimensional, having some arrays as elements, which has multiple key-value pairs as data. You can use the following to re-enter the "data" as desired:
<?php
$info = array( array('name'=>'John'), array('family' => 'Goldenberg'), array('age' => 21));
$out = array();
foreach($info as $arr)
foreach($arr as $key => $val)
$out[$key] = $val;
print_r($out);
?>
+2
source to share