0

I have this nested array of associative array in php.

$input = array(array(
   array('title'=>"Dynamic Title 1", 'content'=>"Dynamic content 1"),
   array('title'=>"Dynamic Title 2", 'content'=>"Dynamic content 2")
));

I want to remove the outermost array such that it becomes;

$input = array(
   array('title'=>"Dynamic Title 1", 'content'=>"Dynamic content 1"),
   array('title'=>"Dynamic Title 2", 'content'=>"Dynamic content 2")
);

I have tried this;

$new_arr = $input[0];

But it did not work. How can the outermost array be removed in php? Thank you very much.

5
  • 6
    That's the correct solution... what happened when you say "it did not work"? Commented Mar 19, 2014 at 9:11
  • It returned only the first record on the array. Commented Mar 19, 2014 at 9:12
  • 1
    It works: ideone.com/GLrOaN Commented Mar 19, 2014 at 9:15
  • To clarify, are you saying when you had the first array from your question, and you ran $new_arr = $input[0] then $new_arr contained array('title'=>"Dynamic Title 1", 'content'=>"Dynamic content 1")? Commented Mar 19, 2014 at 9:16
  • I made some careless mistake in my original code. Stupid me. Yes, it works. Commented Mar 19, 2014 at 9:26

1 Answer 1

1

You can try with foreach like

$input = array(array(
                   array('title'=>"Dynamic Title 1", 'content'=>"Dynamic content 1"),
                   array('title'=>"Dynamic Title 2", 'content'=>"Dynamic content 2")
         )); 
foreach($input as $temp) {
   $newArr = $temp;
}
print_r($newArr);

It also works as you have tried with $input[0].

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.