I have a list of arrays (or objects, they are coming from a database via the PDO fetchAll() function, so both options are OK for me). I wish to convert the list of arrays to an associative array of arrays with the key of each array being one of its columns.
I can obviously do a loop, but I am wondering whether there is some PHP function which already does this, maybe in a more efficient way.
So to illustrate it, lets say I have an array (non-associative) with arrays inside:
[0] => {'name' : 'Joe', 'surname' : 'Bloggs', 'id' : '12345'}
[1] => {'name' : 'Sandy', 'surname' : 'Smith', 'id' : '54321'}
I wish to convert it to:
['12345'] => {'name' : 'Joe', 'surname' : 'Bloggs', 'id' : '12345'}
['54321'] => {'name' : 'Sandy', 'surname' : 'Smith', 'id' : '54321'}
PDO::FETCH_OBJ. So both options OK for me if an elegant technique exists (which does not involve looping).