3v4l.org

run code in 300+ PHP versions simultaneously
<?php $dbData = [ ["rate"=>'["1.55","1","1","1"]'], ["rate"=>'["2.55","2.55","2.55","2.55"]'], ["rate"=>'["1","1","1","1"]'], ["rate"=>'["1.55","2.55","3.55","4.56"]'] ]; $rate = array_map(function($a){ return json_decode($a['rate']); },$dbData); var_dump($rate); /* Replace by code above $rate = [ ["1.55","1","1","1"], ["2.55","2.55","2.55","2.55"], ["1","1","1","1"], ["1.2","1.21","1.2","1.2"] ]; */ $results =[]; // Count the columns in the first row for ($i = 0; $i<sizeof ($rate[0]); $i++) { // Extract each column in turn $col = array_column($rate, $i); // Calculate and store the averages $results[]= array_sum($col)/count($col); } var_dump($results);
Output for git.master_jit, git.master, rfc.property-hooks
array(4) { [0]=> array(4) { [0]=> string(4) "1.55" [1]=> string(1) "1" [2]=> string(1) "1" [3]=> string(1) "1" } [1]=> array(4) { [0]=> string(4) "2.55" [1]=> string(4) "2.55" [2]=> string(4) "2.55" [3]=> string(4) "2.55" } [2]=> array(4) { [0]=> string(1) "1" [1]=> string(1) "1" [2]=> string(1) "1" [3]=> string(1) "1" } [3]=> array(4) { [0]=> string(4) "1.55" [1]=> string(4) "2.55" [2]=> string(4) "3.55" [3]=> string(4) "4.56" } } array(4) { [0]=> float(1.6624999999999999) [1]=> float(1.775) [2]=> float(2.025) [3]=> float(2.2775) }

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