Microsoft
Software
Hardware
Network
Question : Collapse a PHP array
Hi Experts,
I'm doing a backing admin screen for a Joomla site.
I have a loop doing a SQL query which assigns the value to an array using this line at the end of the loop. $players1[$i] = $db->loadObjectList(); // $i is the loop counter and is stepped by one each time
Everything works great with the loop etc... and when I print_r I can see the array has the correct values in it. The trouble is that it creates a multidimensional array that has one too many levels. Have a look:
[0] => Array ( [0] => stdClass Object ( [id] => 7 [p_name] => Napoleon Toshiba ) )
[1] => Array ( [0] => stdClass Object ( [id] => 6 [p_name] => John Doe ) ) )
This array is being assigned to a Joomla select list (drop list) and this extra dimension is really screwing it up. It would be nice if I could collapse it some how to read like this instead:
[0] => [id] => 7 [p_name] => Napoleon Toshiba
[1] => [id] => 6 [p_name] => John Doe
Anyone out there have any ideas?
Thanks!
HNM
Answer : Collapse a PHP array
Iterate through the result array and put them into the array:
$rows = $db->loadObjectList();
foreach ( $rows as $row ) {
$players1[$i] = $row;
$i++;
}
Random Solutions
DB owner
SendKeys in mex file
SBS 2003 Connectcomputer Wizard (via VPN)???
How to add Ajax Extensions 1.0 library to ASP.NET 2.0?
OWA 2010 only working with basic authentication
Is it required to register PTR record for all the domains which uses the same IP Address?
JavaScript: Get first jpg image
SQL Clustering
limiting resources to users
Protect a Partition - Use Bitlocker or Something Else?