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.



Your result can be seen below.

Result of php executing





Full code of array_column and summ.php

  1. <?php
  2. $offer = array(
  3.     932164 => array(
  4.         "ID" => 932164,
  5.         "IBLOCK_ID" => 20,
  6.         "NAME" => "Корм для собак породы пудель Royal canin poodle adult 85 г пауч паштет",
  7.         "CATALOG_QUANTITY" => "8",
  8.         "PRICE_1" => "66.00"
  9.     ),
  10.     1134467 => array(
  11.         "ID" => 1134467,
  12.         "IBLOCK_ID" => 20,
  13.         "NAME" => "Корм для собак породы пудель Royal canin poodle adult 85 г пауч паштет",
  14.         "CATALOG_QUANTITY" => "2",
  15.         "PRICE_1" => "66.00"
  16.     )
  17. );
  18.  
  19. $result = (function($res = 0) use ($offer){
  20.     foreach (array_column($offer, 'CATALOG_QUANTITY') as $val)
  21.         $res += intval($val);
  22.     return $res;
  23. })();
  24.  
  25. var_dump($result);
  26.  
File Description
  • array_column and summ
  • PHP Code
  • 09 Jul-2020
  • 747 Bytes
You can Share it: