3v4l.org

run code in 300+ PHP versions simultaneously
<?php function oldGetMinPrice($num1, $num2) { if(!(is_numeric($num1) && $num1 >0) && !(is_numeric($num2) && $num2 >0) ) { return 'error'; } $num1 = (float)$num1; $num2 = (float)$num2; echo "($num1 & $num2) "; if($num1 <= 0) { return $num2; } if($num2 <= 0) { return $num1; } return min($num1,$num2); } function newGetMinPrice($nums) { $nums = array_filter($nums, function($v){ return (float)$v > 0;}); // convert to float and check if greater than 0 if (empty($nums)) { return 'error'; // if no qualifying prices, return error } return min($nums); // return the lowest qualifying price } $tests = [[0, .1], [1, 'foo'], [.24, -.25], [3, 3], ['foo', 'bar'], [-0, 0.1], [90, -90], [0, 0], [1, 1]]; foreach ($tests as $test) { echo "old: {$test[0]} -vs- {$test[1]} = ",oldGetMinPrice($test[0], $test[1]), "\n"; echo "new: {$test[0]} -vs- {$test[1]} = ",newGetMinPrice($test), "\n\n"; }
Output for git.master, git.master_jit, rfc.property-hooks
old: 0 -vs- 0.1 = (0 & 0.1) 0.1 new: 0 -vs- 0.1 = 0.1 old: 1 -vs- foo = (1 & 0) 1 new: 1 -vs- foo = 1 old: 0.24 -vs- -0.25 = (0.24 & -0.25) 0.24 new: 0.24 -vs- -0.25 = 0.24 old: 3 -vs- 3 = (3 & 3) 3 new: 3 -vs- 3 = 3 old: foo -vs- bar = error new: foo -vs- bar = error old: 0 -vs- 0.1 = (0 & 0.1) 0.1 new: 0 -vs- 0.1 = 0.1 old: 90 -vs- -90 = (90 & -90) 90 new: 90 -vs- -90 = 90 old: 0 -vs- 0 = error new: 0 -vs- 0 = error old: 1 -vs- 1 = (1 & 1) 1 new: 1 -vs- 1 = 1

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:
97.89 ms | 406 KiB | 5 Q