Answer the question
In order to leave comments, you need to log in
How to sum values from PHP arrays?
I have a huge array:
["data"]=>
array(133) {
[0]=>
array(2) {
["dimensions"]=>
array(3) {
[0]=>
array(3) {
["name"]=>
string(6) "Google"
["id"]=>
string(6) "google"
["favicon"]=>
string(10) "google.com"
}
[1]=>
array(3) {
["name"]=>
string(22) "Google, search results"
["id"]=>
string(13) "google_search"
["favicon"]=>
string(10) "google.com"
}
[2]=>
array(3) {
["name"]=>
NULL
["favicon"]=>
NULL
["url"]=>
NULL
}
}
["metrics"]=>
array(1) {
[0]=>
float(328)
}
}
[1]=>
array(2) {
["dimensions"]=>
array(3) {
[0]=>
array(3) {
["name"]=>
string(6) "Yandex"
["id"]=>
string(6) "yandex"
["favicon"]=>
string(13) "www.yandex.ru"
}
[1]=>
array(3) {
["name"]=>
string(22) "Yandex, search results"
["id"]=>
string(13) "yandex_search"
["favicon"]=>
string(13) "www.yandex.ru"
}
[2]=>
array(3) {
["name"]=>
NULL
["favicon"]=>
NULL
["url"]=>
NULL
}
}
["metrics"]=>
array(1) {
[0]=>
float(54)
}
}
[2]=>
array(2) {
["dimensions"]=>
array(3) {
[0]=>
array(3) {
["name"]=>
string(6) "Yandex"
["id"]=>
string(6) "yandex"
["favicon"]=>
string(13) "www.yandex.ru"
}
[1]=>
array(3) {
["name"]=>
string(22) "Yandex, search results"
["id"]=>
string(13) "yandex_search"
["favicon"]=>
string(13) "www.yandex.ru"
}
[2]=>
array(3) {
["name"]=>
string(21) "тюмень софт"
["favicon"]=>
string(13) "www.yandex.ru"
["url"]=>
string(94) "https://yandex.ru/search/?text=%D1%82%D1%8E%D0%BC%D0%B5%D0%BD%D1%8C%20%D1%81%D0%BE%D1%84%D1%82"
}
}
["metrics"]=>
array(1) {
[0]=>
float(41)
}
}
[3]=>
array(2) {
["dimensions"]=>
array(3) {
[0]=>
array(3) {
["name"]=>
string(6) "Yandex"
["id"]=>
string(6) "yandex"
["favicon"]=>
string(13) "www.yandex.ru"
}
[1]=>
array(3) {
["name"]=>
string(22) "Yandex, search results"
["id"]=>
string(13) "yandex_search"
["favicon"]=>
string(13) "www.yandex.ru"
}
[2]=>
array(3) {
["name"]=>
string(11) "tyumen soft"
["favicon"]=>
string(13) "www.yandex.ru"
["url"]=>
string(44) "https://yandex.ru/search/?text=tyumen%20soft"
}
}
["metrics"]=>
array(1) {
[0]=>
float(22)
}
}
[4]=>....
<?foreach ($shablon['data'] as $arShablon):?>
<?if($arShablon['dimensions']['0']['name'] == 'Yandex'):?>
<?=$yandex = array_sum($arShablon['metrics'])?>
<?endif;?>
<?endforeach;?>
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question