PHPize Online / SQLize Online  /  SQLtest Online

A A A
Share      Blog   Popular
Copy Format Clear
CREATE TABLE office_layout ( floor INT, office INT ); INSERT INTO office_layout (floor, office) VALUES (1, 4), (2, 4), (3, 3), (4, 3), (1, 5), (2, 5), (3, 4), (4, 4), (1, 6), (2, 6), (3, 5), (4, 5), (2, 7), (3, 6), (4, 6), (3, 7), (4, 7);
Copy Clear
Copy Format Clear
<?php $sql = <<<SQL SELECT * FROM office_layout ORDER BY floor, office SQL; $result = $mysqli->query($sql)->fetch_all(MYSQLI_ASSOC); array_multisort( array_map( function ($row) { static $c; return $c[$row['floor']] = ($c[$row['floor']] ?? 0) + 1; }, $result ), $result ); var_export($result);
Show:  
Copy Clear