array_column and summ - PHP Online
Form of PHP Sandbox
Enter Your PHP code here for testing/debugging in the Online PHP Sandbox. As in the usual PHP files, you can also add HTML, but do not forget to add the tag <?php
in the places where the PHP script should be executed.
Result of php executing
Full code of array_column and summ.php
- <?php
- $offer = array(
- 932164 => array(
- "ID" => 932164,
- "IBLOCK_ID" => 20,
- "NAME" => "Корм для собак породы пудель Royal canin poodle adult 85 г пауч паштет",
- "CATALOG_QUANTITY" => "8",
- "PRICE_1" => "66.00"
- ),
- 1134467 => array(
- "ID" => 1134467,
- "IBLOCK_ID" => 20,
- "NAME" => "Корм для собак породы пудель Royal canin poodle adult 85 г пауч паштет",
- "CATALOG_QUANTITY" => "2",
- "PRICE_1" => "66.00"
- )
- );
- $result = (function($res = 0) use ($offer){
- foreach (array_column($offer, 'CATALOG_QUANTITY') as $val)
- $res += intval($val);
- return $res;
- })();
- var_dump($result);