I am still new to PHP.
My problem: Warning: array_push() expects parameter 1 to be array
Description: I have a list of room numbers that I am parsing. The first number of the room number refers to the floor of the room. I want to create a 2d array that holds floor numbers, and each floor consists of the rooms.
Code:
$array = self::getAllRooms();
$floorArray = array();
foreach($array as $row)
{
$floorNum = substr($row['room_no'],0,1);
if (in_array($floorNum, $floorArray))
{
array_push($floorArray[$floorNum], $row['room_no']);
}
else
{
array_push($floorArray, $floorNum);
array_push($floorArray[$floorNum], $row['room_no']);
}
}
How do I append the room numbers to the "1" category referring to floor 1?
Thanks a lot!