3v4l.org

run code in 200+ php & hhvm versions
Bugs & Features
<?php class Gridizer { /** * Get a squar-ish grid */ public function getGrid($array) { $grid_size = floor(sqrt(count($array))); $table = $this->chunk($table_cells, max($grid_size, 1)); foreach ($table as $row) { echo implode(' | ', $row) . PHP_EOL; } } /** * Create a Generator to chunk an incoming array into `$chunk_size` sized chunks */ public function chunk(array $array, $chunk_size) { $index = 0; while ($index < count($array)) { yield array_slice($array, $index, $chunk_size, true); $index += $chunk_size; } } } $foo = new Gridizer; echo $foo->getGrid(range(1, 100));
based on 3SZpe
Output for 7.1.0 - 7.2.0
Notice: Undefined variable: table_cells in /in/TGhWR on line 12 Fatal error: Uncaught TypeError: Argument 1 passed to Gridizer::chunk() must be of the type array, null given, called in /in/TGhWR on line 12 and defined in /in/TGhWR:22 Stack trace: #0 /in/TGhWR(12): Gridizer->chunk(NULL, 10) #1 /in/TGhWR(34): Gridizer->getGrid(Array) #2 {main} thrown in /in/TGhWR on line 22
Process exited with code 255.
Output for 7.0.0 - 7.0.20
Notice: Undefined variable: table_cells in /in/TGhWR on line 12 Fatal error: Uncaught TypeError: Argument 1 passed to Gridizer::chunk() must be of the type array, null given, called in /in/TGhWR on line 14 and defined in /in/TGhWR:22 Stack trace: #0 /in/TGhWR(14): Gridizer->chunk(NULL, 10) #1 /in/TGhWR(34): Gridizer->getGrid(Array) #2 {main} thrown in /in/TGhWR on line 22
Process exited with code 255.
Output for 5.5.24 - 5.6.21
Notice: Undefined variable: table_cells in /in/TGhWR on line 12 Catchable fatal error: Argument 1 passed to Gridizer::chunk() must be of the type array, null given in /in/TGhWR on line 22
Process exited with code 255.
Output for 5.4.1 - 5.4.45
Parse error: syntax error, unexpected 'array_slice' (T_STRING) in /in/TGhWR on line 26
Process exited with code 255.
Output for 5.3.18 - 5.3.29
Parse error: syntax error, unexpected T_STRING in /in/TGhWR on line 26
Process exited with code 255.