3v4l.org

run code in 300+ PHP versions simultaneously
<?php $list = array("A","B","C","D"); echo "Array current foreach value as variable expression\n"; debug_zval_dump($list); foreach ( $list as $index => $var ) { echo "Iteration #$index:\n"; debug_zval_dump($list); print(current($list)); } echo "\nArray current foreach value as function parameter\n"; debug_zval_dump($list); foreach ( $list as $var ) { echo "Iteration #$index:\n"; print(item($list)); } function item($list) { debug_zval_dump($list); return current($list); } echo "\nArray as function parameter:\n"; item2($list); function item2($list) { debug_zval_dump($list); foreach ( $list as $var ) { echo "Iteration #$index:\n"; debug_zval_dump($list); print(current($list)); } } ?>
Output for git.master, git.master_jit, rfc.property-hooks
Array current foreach value as variable expression array(4) refcount(3){ [0]=> string(1) "A" interned [1]=> string(1) "B" interned [2]=> string(1) "C" interned [3]=> string(1) "D" interned } Iteration #0: array(4) refcount(4){ [0]=> string(1) "A" interned [1]=> string(1) "B" interned [2]=> string(1) "C" interned [3]=> string(1) "D" interned } AIteration #1: array(4) refcount(4){ [0]=> string(1) "A" interned [1]=> string(1) "B" interned [2]=> string(1) "C" interned [3]=> string(1) "D" interned } AIteration #2: array(4) refcount(4){ [0]=> string(1) "A" interned [1]=> string(1) "B" interned [2]=> string(1) "C" interned [3]=> string(1) "D" interned } AIteration #3: array(4) refcount(4){ [0]=> string(1) "A" interned [1]=> string(1) "B" interned [2]=> string(1) "C" interned [3]=> string(1) "D" interned } A Array current foreach value as function parameter array(4) refcount(3){ [0]=> string(1) "A" interned [1]=> string(1) "B" interned [2]=> string(1) "C" interned [3]=> string(1) "D" interned } Iteration #3: array(4) refcount(5){ [0]=> string(1) "A" interned [1]=> string(1) "B" interned [2]=> string(1) "C" interned [3]=> string(1) "D" interned } AIteration #3: array(4) refcount(5){ [0]=> string(1) "A" interned [1]=> string(1) "B" interned [2]=> string(1) "C" interned [3]=> string(1) "D" interned } AIteration #3: array(4) refcount(5){ [0]=> string(1) "A" interned [1]=> string(1) "B" interned [2]=> string(1) "C" interned [3]=> string(1) "D" interned } AIteration #3: array(4) refcount(5){ [0]=> string(1) "A" interned [1]=> string(1) "B" interned [2]=> string(1) "C" interned [3]=> string(1) "D" interned } A Array as function parameter: array(4) refcount(4){ [0]=> string(1) "A" interned [1]=> string(1) "B" interned [2]=> string(1) "C" interned [3]=> string(1) "D" interned } Warning: Undefined variable $index in /in/37R4u on line 35 Iteration #: array(4) refcount(5){ [0]=> string(1) "A" interned [1]=> string(1) "B" interned [2]=> string(1) "C" interned [3]=> string(1) "D" interned } A Warning: Undefined variable $index in /in/37R4u on line 35 Iteration #: array(4) refcount(5){ [0]=> string(1) "A" interned [1]=> string(1) "B" interned [2]=> string(1) "C" interned [3]=> string(1) "D" interned } A Warning: Undefined variable $index in /in/37R4u on line 35 Iteration #: array(4) refcount(5){ [0]=> string(1) "A" interned [1]=> string(1) "B" interned [2]=> string(1) "C" interned [3]=> string(1) "D" interned } A Warning: Undefined variable $index in /in/37R4u on line 35 Iteration #: array(4) refcount(5){ [0]=> string(1) "A" interned [1]=> string(1) "B" interned [2]=> string(1) "C" interned [3]=> string(1) "D" interned } A

This tab shows result from various feature-branches currently under review by the php developers. Contact me to have additional branches featured.

Active branches

Archived branches

Once feature-branches are merged or declined, they are no longer available. Their functionality (when merged) can be viewed from the main output page


preferences:
43.74 ms | 409 KiB | 8 Q