Hi! Could we please enable some services and cookies to improve your experience and our website?

PHPize Online / SQLize Online  /  SQLtest Online

A A A
Login    Share code      Blog   FAQ

Online Sandbox for SQL and PHP: Write, Run, Test, and Share SQL Queries and PHP Code

Copy Format Clear
CREATE TABLE room ( ID int primary key auto_increment, roomnumber varchar(255) not null, guestcount varchar (255) not null ); INSERT INTO room (ID, roomnumber, guestcount) VALUES ('1', '100', '100'), ('2', '200', '200'), ('3', '300', '50'), ('4', '200', '75'), ('5', '300', '1000');

Stuck with a problem? Got Error? Ask AI support!

Copy Clear
Copy Format Clear
<?php // $mysqli is already declared as a working database connection by this sandbox $room = []; foreach ($mysqli->query("SELECT roomnumber, guestcount FROM room") as $row) { $room[$row['roomnumber']][] = $row['guestcount']; } var_export($room); echo "\n---\n"; var_export(array_keys($room));
Copy Clear