Reputation: 131
I am trying to implement the logic below in a foreach loop where $rooms is a database object returned. I want to separate the data into 5 different arrays with the size of each array depending on the number of rooms returned from the database. Whenever I implement the function below, it provides me with a Call to undefined method stdClass::number_format() where i think my arrays are getting cast to stdClass. I looked around the site and found people with the same problem but no fixes. How can I perform this in php?
Thanks in advance
Code:
...
$rooms = $db->query($sql, PDO::FETCH_OBJ);
$barray = array();
$rarray = array();
$darray = array();
$latarray = array();
$lonarray = array();
$i = 0;
foreach ($rooms as $room):
$barray[i] = $room->Bldg;
$rarray[i] = $room->Room;
$darray[i] = $room->number_format($room->D,9);
$latarray[i] = number_format($room->Latitude,7,".","");
$lonarray[i] = number_format($room->Longitude,7,".","");
$i = $i + 1;
endforeach
?>
Upvotes: 0
Views: 6161
Reputation: 13766
$darray[i] = $room->number_format($room->D,9);
... should be...
$darray[i] = number_format($room->D,9);
Upvotes: 2