3v4l.org

run code in 300+ PHP versions simultaneously
<?php $arr = array( "@context" => "http://schema.org", "@type" => "BreadcrumbList", "itemListElement" => array([ "@type" => "ListItem", "position" => 1, "item" =>[ "@id" => "www.example.com/", "name" => "Home" ] //I need $lab[] to show here ]) ); $i = 1; foreach ($pages as $page) { $i++; $arr['itemListElement'][] = [ '@type' => 'ListItem', 'position' => $i, 'item' => [ "@id" => $page->getUri(), "name" =>$page->getLabel() ]]; } var_dump($arr,$lab); json_encode($arr);
Output for 8.0.0 - 8.0.30, 8.1.0 - 8.1.28, 8.2.0 - 8.2.18, 8.3.0 - 8.3.4, 8.3.6
Warning: Undefined variable $pages in /in/GZbfB on line 19 Warning: foreach() argument must be of type array|object, null given in /in/GZbfB on line 19 Warning: Undefined variable $lab in /in/GZbfB on line 30 array(3) { ["@context"]=> string(17) "http://schema.org" ["@type"]=> string(14) "BreadcrumbList" ["itemListElement"]=> array(1) { [0]=> array(3) { ["@type"]=> string(8) "ListItem" ["position"]=> int(1) ["item"]=> array(2) { ["@id"]=> string(16) "www.example.com/" ["name"]=> string(4) "Home" } } } } NULL
Output for 8.3.5
Warning: PHP Startup: Unable to load dynamic library 'sodium.so' (tried: /usr/lib/php/8.3.5/modules/sodium.so (libsodium.so.23: cannot open shared object file: No such file or directory), /usr/lib/php/8.3.5/modules/sodium.so.so (/usr/lib/php/8.3.5/modules/sodium.so.so: cannot open shared object file: No such file or directory)) in Unknown on line 0 Warning: Undefined variable $pages in /in/GZbfB on line 19 Warning: foreach() argument must be of type array|object, null given in /in/GZbfB on line 19 Warning: Undefined variable $lab in /in/GZbfB on line 30 array(3) { ["@context"]=> string(17) "http://schema.org" ["@type"]=> string(14) "BreadcrumbList" ["itemListElement"]=> array(1) { [0]=> array(3) { ["@type"]=> string(8) "ListItem" ["position"]=> int(1) ["item"]=> array(2) { ["@id"]=> string(16) "www.example.com/" ["name"]=> string(4) "Home" } } } } NULL
Output for 7.1.0 - 7.1.20, 7.2.0 - 7.2.33, 7.3.16 - 7.3.31, 7.4.0 - 7.4.33
Notice: Undefined variable: pages in /in/GZbfB on line 19 Warning: Invalid argument supplied for foreach() in /in/GZbfB on line 19 Notice: Undefined variable: lab in /in/GZbfB on line 30 array(3) { ["@context"]=> string(17) "http://schema.org" ["@type"]=> string(14) "BreadcrumbList" ["itemListElement"]=> array(1) { [0]=> array(3) { ["@type"]=> string(8) "ListItem" ["position"]=> int(1) ["item"]=> array(2) { ["@id"]=> string(16) "www.example.com/" ["name"]=> string(4) "Home" } } } } NULL
Output for 7.3.32 - 7.3.33
Warning: Invalid argument supplied for foreach() in /in/GZbfB on line 19 array(3) { ["@context"]=> string(17) "http://schema.org" ["@type"]=> string(14) "BreadcrumbList" ["itemListElement"]=> array(1) { [0]=> array(3) { ["@type"]=> string(8) "ListItem" ["position"]=> int(1) ["item"]=> array(2) { ["@id"]=> string(16) "www.example.com/" ["name"]=> string(4) "Home" } } } } NULL

preferences:
160.36 ms | 402 KiB | 162 Q