"years": {
"2016": [1, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0],
"2017": [0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0],
"2018": [0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0],
"2019": [0, 0, 0, 0, 2, 0, 0, 0, 0, 0, 0, 0],
"2020": [0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0],
"2008": [0, 0, 0, 0, 0, 0, 0, 1, 7, 6, 4, 6],
"2009": [1, 4, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
"2010": [0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
"2011": [0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
"2013": [1, 0, 0, 3, 3, 0, 0, 0, 0, 0, 0, 0],
"2014": [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1],
"2015": [0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 0, 0]
},Üsteki gibi bir verim var bu verinin içindeki değerlerin nasıl toplarım kolay bir şekilde. Sonuç 48 çıkması lazım.
Array içindeki verileri nasıl toplarım?
8
●90
- 20-08-2021, 11:16:41Merhabalar;
- 20-08-2021, 11:29:17Arrayı değişkene arayıp
print_r(array_sum($b))
Bunu deneyebilir misiniz - 20-08-2021, 11:30:50
<?php $jsonY = '{"years": { "2016": [1, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0], "2017": [0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0], "2018": [0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0], "2019": [0, 0, 0, 0, 2, 0, 0, 0, 0, 0, 0, 0], "2020": [0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0], "2008": [0, 0, 0, 0, 0, 0, 0, 1, 7, 6, 4, 6], "2009": [1, 4, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], "2010": [0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], "2011": [0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], "2013": [1, 0, 0, 3, 3, 0, 0, 0, 0, 0, 0, 0], "2014": [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1], "2015": [0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 0, 0] }}'; $arrayY = json_decode($jsonY, true); $count = 0; foreach ($arrayY['years'] as $year){ $count += array_sum($year); } echo $count; ?>Böyle bir şey yapabilirsiniz. - 20-08-2021, 11:31:35
$jsonString = '{ "years": { "2016": [1, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0], "2017": [0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0], "2018": [0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0], "2019": [0, 0, 0, 0, 2, 0, 0, 0, 0, 0, 0, 0], "2020": [0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0], "2008": [0, 0, 0, 0, 0, 0, 0, 1, 7, 6, 4, 6], "2009": [1, 4, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], "2010": [0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], "2011": [0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], "2013": [1, 0, 0, 3, 3, 0, 0, 0, 0, 0, 0, 0], "2014": [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1], "2015": [0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 0, 0] } }'; // array dönüştürülüyor $arr = json_decode($jsonString, true); $total = 0; foreach ($arr["years"] as $item) { $total += array_sum($item); } print_r($total); - 20-08-2021, 11:33:01
- 20-08-2021, 11:37:51
- 20-08-2021, 11:39:40Seninde ellerine sağlık, teşekkürler.voLwy adlı üyeden alıntı: mesajı görüntüle
Ellerine sağlık