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
Access Export Formatting
SBS 2008 / Connect to SBS 2008 VPN
Rename table with dependancies in SQL Server 2005
Error occured while running a report. (Exception Of Type (System. OutofMemoryException) was thrown)
Formatting a Western Digital Passport without the VCD or 'Smartware'
Exchange 2003 not processing emails
Matrix Background Color
Database Design Question - SQL Server
Regex for number and string
Batch File Check For Numeric Digits