Reputation: 8705
How can I flatten array with only one item (I want to avoid using $array[0]['name']? Array is looking like this:
array (size=1)
0 =>
array (size=2)
'project_id' => string '28'
'project_name' => string 'Test User'
Upvotes: 1
Views: 945
Reputation: 78
use current
current($arr)
it would return false, if the array has no items
see: http://php.net/manual/en/function.current.php
Upvotes: 2
Reputation: 32
Simply create a new variable
$flatArray = $arr[0];
$flatArray['name'];
Or use array_pop
$flatArray = array_pop($arr);
Upvotes: -1