rrre - 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 rrre.php

  1. <?php
  2. $str = '[
  3. {"Наименование": "Дверь-купе Зеркало 600", "Вес":17.500, "Объем":0.056, "Высота":2.090, "Ширина":0.600,"Глубина":0.045},
  4. {"Наименование": "Дверь-купе Зеркало 600", "Вес":17.500, "Объем":0.056, "Высота":2.090, "Ширина":0.600,"Глубина":0.045},
  5. {"Наименование": "Комплект П-2 1200", "Вес":41.500, "Объем":0.089, "Высота":1.210, "Ширина":0.610,"Глубина":0.120},
  6. {"Наименование": "Комплект стоевых", "Вес":39.000, "Объем":0.071, "Высота":2.110, "Ширина":0.610,"Глубина":0.055}
  7. ]';
  8.  
  9. $digit["Height"]["dig"] = array();
  10. $digit["Height"]["summ"] = 0;
  11. $digit["Width"]["dig"] = array();
  12. $digit["Width"]["summ"] = 0;
  13. $digit["Depth"]["dig"] = array();
  14. $digit["Depth"]["summ"] = 0;
  15. $digit["Mass"]["dig"] = array();
  16. $digit["Mass"]["summ"] = 0;
  17. //var_dump ($digit);
  18.  
  19. preg_match_all('/\{(.*?)\}/',$str,$out, PREG_PATTERN_ORDER);
  20.  
  21. foreach ($out[0] as $key => $value)
  22. {
  23.     $line = json_decode($value,true,JSON_UNESCAPED_UNICODE);
  24.     
  25.     $digit["Height"]["dig"][$key] = $line['Высота'];
  26.     $digit["Height"]["summ"] += $line['Высота'];
  27.     
  28.     $digit["Width"]["dig"][$key] = $line['Ширина'];
  29.     $digit["Width"]["summ"] += $line['Ширина'];
  30.     
  31.     $digit["Depth"]["dig"][$key] = $line['Глубина'];
  32.     $digit["Depth"]["summ"] += $line['Глубина'];
  33.     
  34.     $digit["Mass"]["dig"][$key] = $line['Вес'];
  35.     $digit["Mass"]["summ"] += $line['Вес'];
  36.  
  37. }
  38.  
  39. print_r($digit);
  40. ?>
File Description
  • rrre
  • PHP Code
  • 31 Mar-2021
  • 1.58 Kb
You can Share it: