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
Remove a tag but leave the text
Mobile Broadband
The Managed Metadata Service or Connection is currently not available
An E-mail from "Nobody"
Removing Quotes From DB Fields
SQL Query syntax
Problem installing Microsoft Exchange 2010
a code behind method that can be called from a javascript and return list of strings
Unable to reach VMware update service. Please try again later
Windows Server 2008 R2 logon problem