N
N
Nikolai2021-06-24 06:06:00
PHP
Nikolai, 2021-06-24 06:06:00

How to find the sum of values ​​of elements of nested associative arrays by key?

Please tell me the easiest way to find the sum of all 'prise' keys.

<?php
$array =[
  ['name' => 'Name1',
  'model => 'Model', 
  'price => 130,
             ],
  ['name' => 'Name2',
  'model => 'Model2'; 
  'price' => 120,
             ],
]

Example code. The number of nested arrays can be different.

PS. I am just learning )

Answer the question

In order to leave comments, you need to log in

1 answer(s)
R
Rsa97, 2021-06-24
@Differman

array_column , array_sum
or array_reduce

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question