3v4l.org

run code in 300+ PHP versions simultaneously
<?php const UNIT_FACTOR = [ 'g' => 1, 'Kg' => 1000, ]; $weights = ['1 Kg','300 g','1.5 Kg','20 g','5 Kg']; $grams = []; foreach ($weights as $weight) { sscanf($weight, '%f%s', $amount, $unit); $grams[] = $amount * UNIT_FACTOR[$unit]; } array_multisort($grams, $weights); var_export($weights);
Output for git.master, git.master_jit, rfc.property-hooks
array ( 0 => '20 g', 1 => '300 g', 2 => '1 Kg', 3 => '1.5 Kg', 4 => '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:
30.43 ms | 405 KiB | 5 Q