3v4l.org

run code in 300+ PHP versions simultaneously
<?php $tests = array(array(0, .1), array(1, 'foo'), array(.24, -.25), array(3, 3), array('foo', 'bar'), array(-0, 0.1), array(90, -90), array(0, 0), array(1, 1)); foreach ($tests as $test) { echo "Raw: {$test[0]} -vs- {$test[1]} , "; $nums = array((float)$test[0],(float)$test[1]); // force input values to float values echo "FloatVals: {$nums[0]} -vs- {$nums[1]} , "; $nums = array_filter($nums, function($v){ return $v > 0;}); // check if greater than 0 if (empty($nums)) { $price = 'error'; //use die(), but I won't for demonstration } else { $price = min($nums); // declare lowest qualifying price } echo "Output: $price\n"; }
Output for 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.33, 8.2.0 - 8.2.29, 8.3.0 - 8.3.25, 8.4.1 - 8.4.13
Raw: 0 -vs- 0.1 , FloatVals: 0 -vs- 0.1 , Output: 0.1 Raw: 1 -vs- foo , FloatVals: 1 -vs- 0 , Output: 1 Raw: 0.24 -vs- -0.25 , FloatVals: 0.24 -vs- -0.25 , Output: 0.24 Raw: 3 -vs- 3 , FloatVals: 3 -vs- 3 , Output: 3 Raw: foo -vs- bar , FloatVals: 0 -vs- 0 , Output: error Raw: 0 -vs- 0.1 , FloatVals: 0 -vs- 0.1 , Output: 0.1 Raw: 90 -vs- -90 , FloatVals: 90 -vs- -90 , Output: 90 Raw: 0 -vs- 0 , FloatVals: 0 -vs- 0 , Output: error Raw: 1 -vs- 1 , FloatVals: 1 -vs- 1 , Output: 1

preferences:
139.53 ms | 409 KiB | 5 Q