массивы - 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 массивы.php

  1. <?php
  2.  
  3. $imgid = [
  4.         '653' => 'http/1',
  5.         '655' => 'http/2',
  6. ];
  7.  
  8. $arResult = [
  9.         'ITEMS' => [
  10.                 'Прибор 1' => 
  11.                 [
  12.                         'img' => '654',
  13.                         'title' => 'img2',
  14.                 ],
  15.             'Прибор 2' =>
  16.             [
  17.                     'img' => '655',
  18.                         'title' => 'img1',       
  19.             ],
  20.         ],
  21. ];
  22.  
  23.  
  24. foreach ($arResult['ITEMS'] as &$item) {
  25.         if (isset($imgid, $item['img'])) {
  26.           $item['img'] = $imgid[$item['img']];
  27.         }
  28. }
  29.  
  30. echo "<pre>";
  31. var_dump($arResult);
  32.  
  33.  
  34. foreach ($arResult['ITEMS'] as $key => &$item) {
  35.     if (in_array($item['img'], array_keys($imgid))) {
  36.         $item["img"] = $imgid[$item['img']];
  37.     }
  38. }
  39.  
  40. echo "<pre>";
  41. var_dump($arResult);
File Description
  • массивы
  • PHP Code
  • 25 Sep-2022
  • 616 Bytes
You can Share it: