3v4l.org

run code in 300+ PHP versions simultaneously
<?php //initialization of an element of GLOBALS $GLOBALS['categories'] = array(1=>'z',2=>'x',3=>'c',4=>'v',5=>'r'); print_r($GLOBALS['categories']); //another element $GLOBALS['videos'] = array(1=>'a',2=>'b',3=>'c',4=>'d'); //some operations $videosCategories = array(1=>array(2,3,4,5),2=>array(12,13,14,15),3=>array(22,23,24,25),4=>array(32,33,34,35)); foreach($videosCategories as $videoId => $categories2) $GLOBALS['videos'][$videoId]['category'] = implode(',',$categories2); //the initial element is reqritten print_r($GLOBALS['categories']);
Output for 8.0.7 - 8.0.30, 8.1.0 - 8.1.33, 8.2.0 - 8.2.29, 8.3.0 - 8.3.25, 8.4.1 - 8.4.12
Array ( [1] => z [2] => x [3] => c [4] => v [5] => r ) Fatal error: Uncaught TypeError: Cannot access offset of type string on string in /in/s7T2o:15 Stack trace: #0 {main} thrown in /in/s7T2o on line 15
Process exited with code 255.
Output for 8.0.0 - 8.0.6
Array ( [1] => z [2] => x [3] => c [4] => v [5] => r ) Warning: Only the first byte will be assigned to the string offset in /in/s7T2o on line 15 Fatal error: Uncaught TypeError: Cannot access offset of type string on string in /in/s7T2o:15 Stack trace: #0 {main} thrown in /in/s7T2o on line 15
Process exited with code 255.
Output for 5.5.0 - 5.5.35, 5.6.0 - 5.6.28, 7.0.0 - 7.0.20, 7.1.0 - 7.1.20, 7.2.0 - 7.2.33, 7.3.16 - 7.3.33, 7.4.0 - 7.4.33
Array ( [1] => z [2] => x [3] => c [4] => v [5] => r ) Warning: Illegal string offset 'category' in /in/s7T2o on line 15 Warning: Illegal string offset 'category' in /in/s7T2o on line 15 Warning: Illegal string offset 'category' in /in/s7T2o on line 15 Warning: Illegal string offset 'category' in /in/s7T2o on line 15 Array ( [1] => z [2] => x [3] => c [4] => v [5] => r )

preferences:
143.09 ms | 411 KiB | 5 Q