3v4l.org

run code in 200+ php & hhvm versions
Bugs & Features
<?php $x=['a','b']; echo "Original\n\n"; for ($i = 0; $i < count($x); $i++) { $target_path = $x[$i]; if($i == 0 ){ $test1 = $target_path; } if($i == 1 ){ $test2 = $target_path; } //This part should output only 2 results but it outputs something different. echo $test1." img 1 <br>"; echo $test2." img 2 <br>"; } echo "Rishi\n\n"; $target_path_arr = array(); for ($i = 0; $i < count($x); $i++) { $target_path = $x[$i]; $target_path_arr[] = $target_path; // use this in future echo $target_path." img ".($i+1)."<br>"; }
based on Lf6GD
Output for 5.6.0 - 5.6.30, hhvm-3.15.4, 7.0.0 - 7.2.0
Original a img 1 <br> Notice: Undefined variable: test2 in /in/nZi0f on line 18 img 2 <br>a img 1 <br>b img 2 <br>Rishi a img 1<br>b img 2<br>