массивы - 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 массивы.php
- <?php
- $imgid = [
- '653' => 'http/1',
- '655' => 'http/2',
- ];
- $arResult = [
- 'ITEMS' => [
- 'Прибор 1' =>
- [
- 'img' => '654',
- 'title' => 'img2',
- ],
- 'Прибор 2' =>
- [
- 'img' => '655',
- 'title' => 'img1',
- ],
- ],
- ];
- foreach ($arResult['ITEMS'] as &$item) {
- if (isset($imgid, $item['img'])) {
- $item['img'] = $imgid[$item['img']];
- }
- }
- echo "<pre>";
- var_dump($arResult);
- foreach ($arResult['ITEMS'] as $key => &$item) {
- if (in_array($item['img'], array_keys($imgid))) {
- $item["img"] = $imgid[$item['img']];
- }
- }
- echo "<pre>";
- var_dump($arResult);