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
How to get back a User Login when have all user files still but login went away from Users Win 7 Pro
Backup Script
Get rows with MAX counts - SQL Server 2000
Outlook 2010 meetings do not appear on share calendars for room locations
Signal/Alert when a file has been placed/created in a directory
Right-click extremely slow on Windows XP
SCCM Site Boundries
Help with top 1 relational query
Lookup and Copy the content from another workbook
php5 classes and lazy loading