문제

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
?>
도움이 되었습니까?

해결책

$darray[i] = $room->number_format($room->D,9);

... should be...

$darray[i] = number_format($room->D,9);
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top