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
VBscript Logon Error
What is this network configuration called so I can Google it?
facebook header.
Issues installing Crystal Report Viewer with cxlibw-1-6.dll Using Package and deployment VB6 and Crystal Version 10
Removing duplicate SPNs (Service Name Providers)
VB.NET 2008 Get resource file as IO.Stream
change win.ini from boot with XP
Fox 9 Creating a pick list
exchange 2010 installation
Use javascript to get the href value of a clicked link