3v4l.org

run code in 500+ PHP versions simultaneously
<?php $weights = ['1 Kg','300 g','1.5 Kg','20.5 g','5 Kg']; $r = []; foreach ($weights as $v) { if (strpos($v, 'g') !== false) {$k = 1;} // 1 g if (strpos($v, 'Kg') !== false) {$k = 1000;} // 1 kilogram = 1000 g $r[floatval($v)*$k] = $v; } ksort($r);//ksort used to sort array by key print_r($r);
Output for git.master, git.master_jit, rfc.property-hooks
Deprecated: Implicit conversion from float 20.5 to int loses precision in /in/1btER on line 12 Array ( [20] => 20.5 g [300] => 300 g [1000] => 1 Kg [1500] => 1.5 Kg [5000] => 5 Kg )

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:
48.68 ms | 1279 KiB | 4 Q