Modifying a query result to return a more usable array with PHP
Hey everyone, I have a query result returned as an array with active record:
Array (
[0] => Array ( [name] => Betty Glassmaker )
[1] => Array ( [name] => John Johnson )
[2] => Array ( [name] => Bill Pratt )
)
But since my query specifically only asks for t开发者_如何学Gohe name column, I would rather the results be modified to reflect this array structure:
Array (
[0] => Betty Glassmaker
[2] => John Johnson
[3] => Bill Pratt
)
What might be the easiest way to get the result I'm looking for?
You could loop through your array, something like this ( not tested )
// $resultset is you multidimensional array
$optimised = Array(); // good habit to initialise before usage.
foreach($resultset as $key => $value){
$optimised[] = $value['name'];
}
Good-luck!
精彩评论