3v4l.org

run code in 300+ PHP versions simultaneously
<?php $json = json_decode('[ { "Date":"2014-12-29", "totalCount":"1" }, { "Date":"2015-02-05", "totalCount":"116" }, { "Date":"2015-02-06", "totalCount":"7" }, { "Date":"2015-02-07", "totalCount":"5" }, { "Date":"2015-02-08", "totalCount":"16" }, { "Date":"2015-02-09", "totalCount":"39" }, { "Date":"2015-02-10", "totalCount":"29" }, { "Date":"2015-02-11", "totalCount":"7" }, { "Date":"2015-02-12", "totalCount":"14" }, { "Date":"2015-02-13", "totalCount":"16" }, { "Date":"2015-02-14", "totalCount":"12" }, { "Date":"2015-02-15", "totalCount":"7" }, { "Date":"2015-02-16", "totalCount":"1" }, { "Date":"2015-02-17", "totalCount":"8" }, { "Date":"2015-02-18", "totalCount":"25" }, { "Date":"2015-02-19", "totalCount":"17" }, { "Date":"2015-02-20", "totalCount":"15" }, { "Date":"2015-02-21", "totalCount":"10" }, { "Date":"2015-02-22", "totalCount":"7" }, { "Date":"2015-02-23", "totalCount":"8" }, { "Date":"2015-02-24", "totalCount":"17" }, { "Date":"2015-02-25", "totalCount":"3" }, { "Date":"2015-02-26", "totalCount":"3" }, { "Date":"2015-02-27", "totalCount":"2" }, { "Date":"2015-02-28", "totalCount":"1" }, { "Date":"2015-03-01", "totalCount":"3" }, { "Date":"2015-03-02", "totalCount":"10" }, { "Date":"2015-03-03", "totalCount":"1" }, { "Date":"2015-03-04", "totalCount":"9" }, { "Date":"2015-03-05", "totalCount":"3" }, { "Date":"2015-03-06", "totalCount":"13" }, { "Date":"2015-03-07", "totalCount":"5" }, { "Date":"2015-03-08", "totalCount":"7" }, { "Date":"2015-03-09", "totalCount":"6" }, { "Date":"2015-03-10", "totalCount":"11" }, { "Date":"2015-03-11", "totalCount":"3" }, { "Date":"2015-03-12", "totalCount":"8" }, { "Date":"2015-03-13", "totalCount":"5" }, { "Date":"2015-03-14", "totalCount":"10" }, { "Date":"2015-03-15", "totalCount":"5" }, { "Date":"2015-03-16", "totalCount":"5" }, { "Date":"2015-03-17", "totalCount":"7" }, { "Date":"2015-03-18", "totalCount":"4" }, { "Date":"2015-03-19", "totalCount":"4" }, { "Date":"2015-03-20", "totalCount":"6" }, { "Date":"2015-03-21", "totalCount":"6" }, { "Date":"2015-03-22", "totalCount":"2" }, { "Date":"2015-03-23", "totalCount":"3" }, { "Date":"2015-03-24", "totalCount":"7" }, { "Date":"2015-03-25", "totalCount":"5" }, { "Date":"2015-03-26", "totalCount":"2" }, { "Date":"2015-03-27", "totalCount":"2" }, { "Date":"2015-03-28", "totalCount":"4" }, { "Date":"2015-03-29", "totalCount":"3" }, { "Date":"2015-03-30", "totalCount":"3" }, { "Date":"2015-03-31", "totalCount":"1" }, { "Date":"2015-04-01", "totalCount":"3" }, { "Date":"2015-04-02", "totalCount":"5" }, { "Date":"2015-04-03", "totalCount":"5" }, { "Date":"2015-04-04", "totalCount":"3" }, { "Date":"2015-04-05", "totalCount":"4" }, { "Date":"2015-04-06", "totalCount":"2" }, { "Date":"2015-04-07", "totalCount":"4" }, { "Date":"2015-04-08", "totalCount":"7" }, { "Date":"2015-04-09", "totalCount":"5" }, { "Date":"2015-04-10", "totalCount":"3" }, { "Date":"2015-04-11", "totalCount":"7" }, { "Date":"2015-04-12", "totalCount":"5" }, { "Date":"2015-04-13", "totalCount":"12" }, { "Date":"2015-04-14", "totalCount":"5" }, { "Date":"2015-04-15", "totalCount":"7" }, { "Date":"2015-04-16", "totalCount":"5" }, { "Date":"2015-04-17", "totalCount":"6" }, { "Date":"2015-04-18", "totalCount":"6" }, { "Date":"2015-04-19", "totalCount":"14" }, { "Date":"2015-04-20", "totalCount":"10" }, { "Date":"2015-04-21", "totalCount":"10" }, { "Date":"2015-04-22", "totalCount":"4" }, { "Date":"2015-04-23", "totalCount":"7" }, { "Date":"2015-04-24", "totalCount":"8" } ]'); $total = 0; $count = count($json); foreach ($json as $key => $obj) { $total += intval($obj->totalCount); $json[$key]->totalTotal = $total; } var_dump($json);
Output for 5.2.0 - 5.2.17, 5.3.0 - 5.3.29, 5.4.0 - 5.4.45, 5.5.0 - 5.5.38, 5.6.0 - 5.6.28, 7.0.0 - 7.0.20, 7.1.0 - 7.1.20, 7.2.0 - 7.2.33, 7.3.16 - 7.3.33, 7.4.0 - 7.4.33, 8.0.0 - 8.0.30, 8.1.0 - 8.1.28, 8.2.0 - 8.2.18, 8.3.0 - 8.3.6
array(80) { [0]=> object(stdClass)#1 (3) { ["Date"]=> string(10) "2014-12-29" ["totalCount"]=> string(1) "1" ["totalTotal"]=> int(1) } [1]=> object(stdClass)#2 (3) { ["Date"]=> string(10) "2015-02-05" ["totalCount"]=> string(3) "116" ["totalTotal"]=> int(117) } [2]=> object(stdClass)#3 (3) { ["Date"]=> string(10) "2015-02-06" ["totalCount"]=> string(1) "7" ["totalTotal"]=> int(124) } [3]=> object(stdClass)#4 (3) { ["Date"]=> string(10) "2015-02-07" ["totalCount"]=> string(1) "5" ["totalTotal"]=> int(129) } [4]=> object(stdClass)#5 (3) { ["Date"]=> string(10) "2015-02-08" ["totalCount"]=> string(2) "16" ["totalTotal"]=> int(145) } [5]=> object(stdClass)#6 (3) { ["Date"]=> string(10) "2015-02-09" ["totalCount"]=> string(2) "39" ["totalTotal"]=> int(184) } [6]=> object(stdClass)#7 (3) { ["Date"]=> string(10) "2015-02-10" ["totalCount"]=> string(2) "29" ["totalTotal"]=> int(213) } [7]=> object(stdClass)#8 (3) { ["Date"]=> string(10) "2015-02-11" ["totalCount"]=> string(1) "7" ["totalTotal"]=> int(220) } [8]=> object(stdClass)#9 (3) { ["Date"]=> string(10) "2015-02-12" ["totalCount"]=> string(2) "14" ["totalTotal"]=> int(234) } [9]=> object(stdClass)#10 (3) { ["Date"]=> string(10) "2015-02-13" ["totalCount"]=> string(2) "16" ["totalTotal"]=> int(250) } [10]=> object(stdClass)#11 (3) { ["Date"]=> string(10) "2015-02-14" ["totalCount"]=> string(2) "12" ["totalTotal"]=> int(262) } [11]=> object(stdClass)#12 (3) { ["Date"]=> string(10) "2015-02-15" ["totalCount"]=> string(1) "7" ["totalTotal"]=> int(269) } [12]=> object(stdClass)#13 (3) { ["Date"]=> string(10) "2015-02-16" ["totalCount"]=> string(1) "1" ["totalTotal"]=> int(270) } [13]=> object(stdClass)#14 (3) { ["Date"]=> string(10) "2015-02-17" ["totalCount"]=> string(1) "8" ["totalTotal"]=> int(278) } [14]=> object(stdClass)#15 (3) { ["Date"]=> string(10) "2015-02-18" ["totalCount"]=> string(2) "25" ["totalTotal"]=> int(303) } [15]=> object(stdClass)#16 (3) { ["Date"]=> string(10) "2015-02-19" ["totalCount"]=> string(2) "17" ["totalTotal"]=> int(320) } [16]=> object(stdClass)#17 (3) { ["Date"]=> string(10) "2015-02-20" ["totalCount"]=> string(2) "15" ["totalTotal"]=> int(335) } [17]=> object(stdClass)#18 (3) { ["Date"]=> string(10) "2015-02-21" ["totalCount"]=> string(2) "10" ["totalTotal"]=> int(345) } [18]=> object(stdClass)#19 (3) { ["Date"]=> string(10) "2015-02-22" ["totalCount"]=> string(1) "7" ["totalTotal"]=> int(352) } [19]=> object(stdClass)#20 (3) { ["Date"]=> string(10) "2015-02-23" ["totalCount"]=> string(1) "8" ["totalTotal"]=> int(360) } [20]=> object(stdClass)#21 (3) { ["Date"]=> string(10) "2015-02-24" ["totalCount"]=> string(2) "17" ["totalTotal"]=> int(377) } [21]=> object(stdClass)#22 (3) { ["Date"]=> string(10) "2015-02-25" ["totalCount"]=> string(1) "3" ["totalTotal"]=> int(380) } [22]=> object(stdClass)#23 (3) { ["Date"]=> string(10) "2015-02-26" ["totalCount"]=> string(1) "3" ["totalTotal"]=> int(383) } [23]=> object(stdClass)#24 (3) { ["Date"]=> string(10) "2015-02-27" ["totalCount"]=> string(1) "2" ["totalTotal"]=> int(385) } [24]=> object(stdClass)#25 (3) { ["Date"]=> string(10) "2015-02-28" ["totalCount"]=> string(1) "1" ["totalTotal"]=> int(386) } [25]=> object(stdClass)#26 (3) { ["Date"]=> string(10) "2015-03-01" ["totalCount"]=> string(1) "3" ["totalTotal"]=> int(389) } [26]=> object(stdClass)#27 (3) { ["Date"]=> string(10) "2015-03-02" ["totalCount"]=> string(2) "10" ["totalTotal"]=> int(399) } [27]=> object(stdClass)#28 (3) { ["Date"]=> string(10) "2015-03-03" ["totalCount"]=> string(1) "1" ["totalTotal"]=> int(400) } [28]=> object(stdClass)#29 (3) { ["Date"]=> string(10) "2015-03-04" ["totalCount"]=> string(1) "9" ["totalTotal"]=> int(409) } [29]=> object(stdClass)#30 (3) { ["Date"]=> string(10) "2015-03-05" ["totalCount"]=> string(1) "3" ["totalTotal"]=> int(412) } [30]=> object(stdClass)#31 (3) { ["Date"]=> string(10) "2015-03-06" ["totalCount"]=> string(2) "13" ["totalTotal"]=> int(425) } [31]=> object(stdClass)#32 (3) { ["Date"]=> string(10) "2015-03-07" ["totalCount"]=> string(1) "5" ["totalTotal"]=> int(430) } [32]=> object(stdClass)#33 (3) { ["Date"]=> string(10) "2015-03-08" ["totalCount"]=> string(1) "7" ["totalTotal"]=> int(437) } [33]=> object(stdClass)#34 (3) { ["Date"]=> string(10) "2015-03-09" ["totalCount"]=> string(1) "6" ["totalTotal"]=> int(443) } [34]=> object(stdClass)#35 (3) { ["Date"]=> string(10) "2015-03-10" ["totalCount"]=> string(2) "11" ["totalTotal"]=> int(454) } [35]=> object(stdClass)#36 (3) { ["Date"]=> string(10) "2015-03-11" ["totalCount"]=> string(1) "3" ["totalTotal"]=> int(457) } [36]=> object(stdClass)#37 (3) { ["Date"]=> string(10) "2015-03-12" ["totalCount"]=> string(1) "8" ["totalTotal"]=> int(465) } [37]=> object(stdClass)#38 (3) { ["Date"]=> string(10) "2015-03-13" ["totalCount"]=> string(1) "5" ["totalTotal"]=> int(470) } [38]=> object(stdClass)#39 (3) { ["Date"]=> string(10) "2015-03-14" ["totalCount"]=> string(2) "10" ["totalTotal"]=> int(480) } [39]=> object(stdClass)#40 (3) { ["Date"]=> string(10) "2015-03-15" ["totalCount"]=> string(1) "5" ["totalTotal"]=> int(485) } [40]=> object(stdClass)#41 (3) { ["Date"]=> string(10) "2015-03-16" ["totalCount"]=> string(1) "5" ["totalTotal"]=> int(490) } [41]=> object(stdClass)#42 (3) { ["Date"]=> string(10) "2015-03-17" ["totalCount"]=> string(1) "7" ["totalTotal"]=> int(497) } [42]=> object(stdClass)#43 (3) { ["Date"]=> string(10) "2015-03-18" ["totalCount"]=> string(1) "4" ["totalTotal"]=> int(501) } [43]=> object(stdClass)#44 (3) { ["Date"]=> string(10) "2015-03-19" ["totalCount"]=> string(1) "4" ["totalTotal"]=> int(505) } [44]=> object(stdClass)#45 (3) { ["Date"]=> string(10) "2015-03-20" ["totalCount"]=> string(1) "6" ["totalTotal"]=> int(511) } [45]=> object(stdClass)#46 (3) { ["Date"]=> string(10) "2015-03-21" ["totalCount"]=> string(1) "6" ["totalTotal"]=> int(517) } [46]=> object(stdClass)#47 (3) { ["Date"]=> string(10) "2015-03-22" ["totalCount"]=> string(1) "2" ["totalTotal"]=> int(519) } [47]=> object(stdClass)#48 (3) { ["Date"]=> string(10) "2015-03-23" ["totalCount"]=> string(1) "3" ["totalTotal"]=> int(522) } [48]=> object(stdClass)#49 (3) { ["Date"]=> string(10) "2015-03-24" ["totalCount"]=> string(1) "7" ["totalTotal"]=> int(529) } [49]=> object(stdClass)#50 (3) { ["Date"]=> string(10) "2015-03-25" ["totalCount"]=> string(1) "5" ["totalTotal"]=> int(534) } [50]=> object(stdClass)#51 (3) { ["Date"]=> string(10) "2015-03-26" ["totalCount"]=> string(1) "2" ["totalTotal"]=> int(536) } [51]=> object(stdClass)#52 (3) { ["Date"]=> string(10) "2015-03-27" ["totalCount"]=> string(1) "2" ["totalTotal"]=> int(538) } [52]=> object(stdClass)#53 (3) { ["Date"]=> string(10) "2015-03-28" ["totalCount"]=> string(1) "4" ["totalTotal"]=> int(542) } [53]=> object(stdClass)#54 (3) { ["Date"]=> string(10) "2015-03-29" ["totalCount"]=> string(1) "3" ["totalTotal"]=> int(545) } [54]=> object(stdClass)#55 (3) { ["Date"]=> string(10) "2015-03-30" ["totalCount"]=> string(1) "3" ["totalTotal"]=> int(548) } [55]=> object(stdClass)#56 (3) { ["Date"]=> string(10) "2015-03-31" ["totalCount"]=> string(1) "1" ["totalTotal"]=> int(549) } [56]=> object(stdClass)#57 (3) { ["Date"]=> string(10) "2015-04-01" ["totalCount"]=> string(1) "3" ["totalTotal"]=> int(552) } [57]=> object(stdClass)#58 (3) { ["Date"]=> string(10) "2015-04-02" ["totalCount"]=> string(1) "5" ["totalTotal"]=> int(557) } [58]=> object(stdClass)#59 (3) { ["Date"]=> string(10) "2015-04-03" ["totalCount"]=> string(1) "5" ["totalTotal"]=> int(562) } [59]=> object(stdClass)#60 (3) { ["Date"]=> string(10) "2015-04-04" ["totalCount"]=> string(1) "3" ["totalTotal"]=> int(565) } [60]=> object(stdClass)#61 (3) { ["Date"]=> string(10) "2015-04-05" ["totalCount"]=> string(1) "4" ["totalTotal"]=> int(569) } [61]=> object(stdClass)#62 (3) { ["Date"]=> string(10) "2015-04-06" ["totalCount"]=> string(1) "2" ["totalTotal"]=> int(571) } [62]=> object(stdClass)#63 (3) { ["Date"]=> string(10) "2015-04-07" ["totalCount"]=> string(1) "4" ["totalTotal"]=> int(575) } [63]=> object(stdClass)#64 (3) { ["Date"]=> string(10) "2015-04-08" ["totalCount"]=> string(1) "7" ["totalTotal"]=> int(582) } [64]=> object(stdClass)#65 (3) { ["Date"]=> string(10) "2015-04-09" ["totalCount"]=> string(1) "5" ["totalTotal"]=> int(587) } [65]=> object(stdClass)#66 (3) { ["Date"]=> string(10) "2015-04-10" ["totalCount"]=> string(1) "3" ["totalTotal"]=> int(590) } [66]=> object(stdClass)#67 (3) { ["Date"]=> string(10) "2015-04-11" ["totalCount"]=> string(1) "7" ["totalTotal"]=> int(597) } [67]=> object(stdClass)#68 (3) { ["Date"]=> string(10) "2015-04-12" ["totalCount"]=> string(1) "5" ["totalTotal"]=> int(602) } [68]=> object(stdClass)#69 (3) { ["Date"]=> string(10) "2015-04-13" ["totalCount"]=> string(2) "12" ["totalTotal"]=> int(614) } [69]=> object(stdClass)#70 (3) { ["Date"]=> string(10) "2015-04-14" ["totalCount"]=> string(1) "5" ["totalTotal"]=> int(619) } [70]=> object(stdClass)#71 (3) { ["Date"]=> string(10) "2015-04-15" ["totalCount"]=> string(1) "7" ["totalTotal"]=> int(626) } [71]=> object(stdClass)#72 (3) { ["Date"]=> string(10) "2015-04-16" ["totalCount"]=> string(1) "5" ["totalTotal"]=> int(631) } [72]=> object(stdClass)#73 (3) { ["Date"]=> string(10) "2015-04-17" ["totalCount"]=> string(1) "6" ["totalTotal"]=> int(637) } [73]=> object(stdClass)#74 (3) { ["Date"]=> string(10) "2015-04-18" ["totalCount"]=> string(1) "6" ["totalTotal"]=> int(643) } [74]=> object(stdClass)#75 (3) { ["Date"]=> string(10) "2015-04-19" ["totalCount"]=> string(2) "14" ["totalTotal"]=> int(657) } [75]=> object(stdClass)#76 (3) { ["Date"]=> string(10) "2015-04-20" ["totalCount"]=> string(2) "10" ["totalTotal"]=> int(667) } [76]=> object(stdClass)#77 (3) { ["Date"]=> string(10) "2015-04-21" ["totalCount"]=> string(2) "10" ["totalTotal"]=> int(677) } [77]=> object(stdClass)#78 (3) { ["Date"]=> string(10) "2015-04-22" ["totalCount"]=> string(1) "4" ["totalTotal"]=> int(681) } [78]=> object(stdClass)#79 (3) { ["Date"]=> string(10) "2015-04-23" ["totalCount"]=> string(1) "7" ["totalTotal"]=> int(688) } [79]=> object(stdClass)#80 (3) { ["Date"]=> string(10) "2015-04-24" ["totalCount"]=> string(1) "8" ["totalTotal"]=> int(696) } }
Output for 5.0.0 - 5.0.5, 5.1.0 - 5.1.6
Fatal error: Call to undefined function json_decode() in /in/jitlI on line 3
Process exited with code 255.
Output for 4.4.5 - 4.4.9
Fatal error: Call to undefined function: json_decode() in /in/jitlI on line 3
Process exited with code 255.
Output for 4.3.2 - 4.3.11, 4.4.0 - 4.4.4
Fatal error: Call to undefined function: json_decode() in /in/jitlI on line 3
Process exited with code 255.
Output for 4.3.0 - 4.3.1
Fatal error: Call to undefined function: json_decode() in /in/jitlI on line 3

preferences:
319.43 ms | 401 KiB | 355 Q