3v4l.org

run code in 300+ PHP versions simultaneously
<?php $json = '[ {name: "KFC", distance: 17, likes: 3}, {name: "Macdonalds", distance: 2, likes: 9}, {name: "Pizza Hut", distance: 9, likes: 12}, {name: "Burger King", distance: 14, likes: 17} ]'; $json = preg_replace('/(\w+)(?=:)/', '"$1"', $json); $restaurants = json_decode($json, true); function get_rating($restaurant, $weights) { $rating = 0; foreach ($weights as $factor => $weight) { $rating += $weight * $restaurant[$factor]; } return $rating; } $weights = array('distance' => -30, 'likes' => 10); usort($restaurants, function ($a, $b) use ($weights) { return get_rating($b, $weights) - get_rating($a, $weights); }); print_r($restaurants);
Output for git.master, git.master_jit, rfc.property-hooks
Array ( [0] => Array ( [name] => Macdonalds [distance] => 2 [likes] => 9 ) [1] => Array ( [name] => Pizza Hut [distance] => 9 [likes] => 12 ) [2] => Array ( [name] => Burger King [distance] => 14 [likes] => 17 ) [3] => Array ( [name] => KFC [distance] => 17 [likes] => 3 ) )

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:
28.26 ms | 407 KiB | 5 Q