0

Eloquent return value in object and use toArray it's look like

array (size=1)
   0 => 
    array (size=5)
      'id' => int 60
      'Name' => string 'ttt' (length=3)
      'Age' => int 444
      'created_at' => string '2013-08-31 13:05:38' (length=19)
      'updated_at' => string '2013-08-31 13:05:38' (length=19)

I use array_flatten for solve this but it's replace key name

 array (size=5)
 0 => int 60
 1 => string 'ttt' (length=3)
 2 => int 444
 3 => string '2013-08-31 13:05:38' (length=19)
 4 => string '2013-08-31 13:05:38' (length=19)

I need to keep key name?

2
  • 1
    Why not just access it with $var[0]? Commented Aug 31, 2013 at 10:51
  • Oop I very very forget it its sorry for poor question Commented Aug 31, 2013 at 11:03

2 Answers 2

1

Assuming your array is in $data, just use:

$data = $data[0];
Sign up to request clarification or add additional context in comments.

Comments

0

With this simple array, you can even 'flatten' it with the following:

$result = $arr[0];

To flatten a more complex 2-dimensional array use something like this:

function nowItIsFlat( $arr ) {
  $output = Array();
  foreach( $arr as $key => $val ) {
    if( is_array( $val ) ) {
      $output = array_merge( $output, $val );
    } else {
      $output[$key] = $val;
    }
  }
  return $output;
}

Obviously any duplicate keys will be overwritten.

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.