3v4l.org

run code in 300+ PHP versions simultaneously
<?php $refs = array(); function wrap( $arr){ // Need to clear out the global references array, I chose to do this here global $refs; $refs = array(); test( $arr); } function test( $arr){ global $refs; $refs[] = $arr; foreach( $arr as $v) { if( in_array( $v, $refs)) { print ' ref '; } else { if( is_array( $v)) { test( $v); } else { print $v . ', '; } } } } echo "Array 1:\n"; $array1 = array(1, 2, 3); $array1[4] = &$array1; wrap( $array1); echo "\nArray 2:\n"; $array2 = array(1, 2, 3, array(1, 2, 3)); $array2[2] = &$array2; wrap( $array2); echo "\nArray 3:\n"; $array3 = array(1, 2, 3, array(1, 2, 3)); $array3[3][1] = &$array3; wrap( $array3);
Output for 5.3.15 - 5.3.29, 5.4.5 - 5.4.45, 5.5.0 - 5.5.38, 5.6.0 - 5.6.40, 7.0.0 - 7.0.33, 7.1.0 - 7.1.33, 7.2.0 - 7.2.33, 7.3.0 - 7.3.33, 7.4.0 - 7.4.33, 8.0.0 - 8.0.30, 8.1.0 - 8.1.27, 8.2.0 - 8.2.17, 8.3.0 - 8.3.4
Array 1: 1, 2, 3, ref Array 2: 1, 2, ref 1, 2, 3, Array 3: 1, 2, 3, 1, ref 3,
Output for 5.2.3 - 5.2.17, 5.3.0 - 5.3.14, 5.4.0 - 5.4.4
Array 1: 1, 2, 3, Fatal error: Nesting level too deep - recursive dependency? in /in/WMZBS on line 15
Process exited with code 255.
Output for 4.3.2 - 4.3.11, 4.4.0 - 4.4.9, 5.0.0 - 5.0.5, 5.1.0 - 5.1.6, 5.2.0 - 5.2.2
Array 1: 1, 2, 3, <br /> <b>Fatal error</b>: Nesting level too deep - recursive dependency? in <b>/in/WMZBS</b> on line <b>15</b><br />
Process exited with code 255.
Output for 4.3.0 - 4.3.1
Array 1: 1, 2, 3, <br /> <b>Fatal error</b>: Nesting level too deep - recursive dependency? in <b>/in/WMZBS</b> on line <b>15</b><br />

preferences:
331.26 ms | 401 KiB | 456 Q