@ilovv
Нуб, нуждающийся в помощи в php

Почему код выводит несколько раз одно и тоже?

<?php
$obj = json_decode('{"1 Часть": {"t13": ["https://gdz-ru.com/attachments/images/tasks/000/109/238/0002/5c373b8ceb0f8.jpg"], "t14": ["https://gdz-ru.com/attachments/images/tasks/000/109/238/0002/5c373b8cec0b4.jpg"], "t16": ["https://gdz-ru.com/attachments/images/tasks/000/109/238/0002/5c373b8cee086.jpg", "https://gdz-ru.com/attachments/images/tasks/000/109/238/0002/5c373b8cee4c9.jpg"], "t19\u201320": ["https://gdz-ru.com/attachments/images/tasks/000/109/238/0002/5c373b8cf079c.jpg"], "t21\u201322": ["https://gdz-ru.com/attachments/images/tasks/000/109/238/0002/5c373b8cf2ae5.jpg", "https://gdz-ru.com/attachments/images/tasks/000/109/238/0002/5c373b8cf2fa0.jpg"], "t28": ["https://gdz-ru.com/attachments/images/tasks/000/109/238/0002/5c373b8d035a9.jpg", "https://gdz-ru.com/attachments/images/tasks/000/109/238/0002/5c373b8d03a6c.jpg"], "t37\u201338": ["https://gdz-ru.com/attachments/images/tasks/000/109/238/0002/5c373b8d04c41.jpg", "https://gdz-ru.com/attachments/images/tasks/000/109/238/0002/5c373b8d05156.jpg", "https://gdz-ru.com/attachments/images/tasks/000/109/238/0002/5c373b8d05647.jpg"], "t39\u201340": ["https://gdz-ru.com/attachments/images/tasks/000/109/238/0002/5c373b8d05ac3.jpg", "https://gdz-ru.com/attachments/images/tasks/000/109/238/0002/5c373b8d05ff0.jpg", "https://gdz-ru.com/attachments/images/tasks/000/109/238/0002/5c373b8d06512.jpg"]}, "2 Часть": {"t5": ["https://gdz-ru.com/attachments/images/tasks/000/109/238/0002/5c373b8d20a76.jpg"], "t6\u20137": ["https://gdz-ru.com/attachments/images/tasks/000/109/238/0002/5c373b8d219bc.jpg"], "t8": ["https://gdz-ru.com/attachments/images/tasks/000/109/238/0002/5c373b8d25274.jpg"], "t9": ["https://gdz-ru.com/attachments/images/tasks/000/109/238/0002/5c373b8d2690d.jpg"], "t10\u201311": ["https://gdz-ru.com/attachments/images/tasks/000/109/238/0002/5c373b8d0dc7c.jpg"], "t12": ["https://gdz-ru.com/attachments/images/tasks/000/109/238/0002/5c373b8d0f8b6.jpg"], "t14": ["https://gdz-ru.com/attachments/images/tasks/000/109/238/0002/5c373b8d11f1c.jpg"], "t16\u201317": ["https://gdz-ru.com/attachments/images/tasks/000/109/238/0002/5c373b8d17016.jpg"], "t19": ["https://gdz-ru.com/attachments/images/tasks/000/109/238/0002/5c373b8d1b0fd.jpg", "https://gdz-ru.com/attachments/images/tasks/000/109/238/0002/5c373b8d1b613.jpg"], "t27": ["https://gdz-ru.com/attachments/images/tasks/000/109/238/0002/5c373b8d1f6be.jpg", "https://gdz-ru.com/attachments/images/tasks/000/109/238/0002/5c373b8d1fc84.jpg"], "t41": ["https://gdz-ru.com/attachments/images/tasks/000/109/238/0002/5c373b8d201de.jpg", "https://gdz-ru.com/attachments/images/tasks/000/109/238/0002/5c373b8d20713.jpg"], "t53": ["https://gdz-ru.com/attachments/images/tasks/000/109/238/0002/5c373b8d20ea4.jpg", "https://gdz-ru.com/attachments/images/tasks/000/109/238/0002/5c373b8d21545.jpg"], "t65": ["https://gdz-ru.com/attachments/images/tasks/000/109/238/0002/5c373b8d21f6e.jpg"]}}',true);
foreach ($obj as $key => $part) { ?>
	<div class="spoiler">
		<div class="spoiler-head"><?php echo $key?></div>
		<?php 
		foreach($part as $k => $a) {
			if ($k[0] !== 't') continue;
			foreach($a as $l) {	
				$res = '<a href="' . $k . '">' . str_replace('t','',$k) . '</a>';
				echo $res;
				echo '<br>';
			}
		}?>
		<div class="spoiler-body extc">
		</div>
	</div>
<?php }
  • Вопрос задан
  • 63 просмотра
Решения вопроса 1
@ilovv Автор вопроса
Нуб, нуждающийся в помощи в php
foreach ($obj as $key => $part) { ?>
	<div class="spoiler">
		<div class="spoiler-head"><?php echo $key?></div>
		<?php 
		foreach($part as $k => $a) {
			$res = '<a href="' . $k . '">' . str_replace('t','',$k) . '</a>';
			echo $res;
			echo '<br>';
		}?>
		<div class="spoiler-body extc">
		</div>
	</div>
<?php }
Ответ написан
Комментировать
Пригласить эксперта
Ваш ответ на вопрос

Войдите, чтобы написать ответ

Похожие вопросы