3

Below is the print_r($result) result of an $result = array_merge(array($id => $value), array($user => $value), array("Information" => $value)) variable in a piece of PHP code:

Array ( [id] => 1 [user] => 1 
    [Information] => Array ( [0] => Array ( [name] => 'John' ) 
                            [1] => Array ( [family] => 'Goldenberg' ) 
                            [2] => Array ( [age] => '21' )))

How to remove the array keys from the "Information" => $value array in PHP to make the output like below:

Array ( [id] => 1 [user] => 1 
    [Information] => Array ([name] => 'John' 
                            [family] => 'Goldenberg' 
                            [age] => '21'))

Is there any specific function in PHP to complete this task? Thanks a lot for your help.

1
  • Please correct the statement in the array_merge(), it's a syntax error. Commented May 30, 2015 at 3:07

1 Answer 1

2

Your "Information" array is a multidimensional one, having some arrays as the elements, in which there are some "key-value" pairs as "data". You may use the following to reinsert the "data" in the desirable way:

<?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);
?>
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.