I have an array like so:
Array
(
[0] => stdClass Object
(
[id] => 12
[name] => Business
)
)
But since it only has 1 index element, how can I make it top level removing the zero index? Because I want to reference this array like so $category->name instead of $category[0]->name
I know I can re-build this with a foreach loop but I was hoping there might be a PHP builtin function that does this?
Do you mean something like this?
Instead of the first line, you could also do
reset()will reset the array pointer to the first element and return that element. So this will also work with an associative array (which might have elements but not one with the index0).