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

Возможно ли перебрать этот json и вывести?

есть json файл:
{"109238": [], "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": ["https://gdz-ru.com/attachments/images/tasks/000/109/238/0002/5c373b8cf079c.jpg"], "t21": ["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": ["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": ["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"], "t46": ["https://gdz-ru.com/attachments/images/tasks/000/109/238/0002/5c373b8d06830.jpg", "https://gdz-ru.com/attachments/images/tasks/000/109/238/0002/5c373b8d06e15.jpg"], "t49": ["https://gdz-ru.com/attachments/images/tasks/000/109/238/0002/5c373b8d0716b.jpg"], "t57": ["https://gdz-ru.com/attachments/images/tasks/000/109/238/0002/5c373b8d0774d.jpg", "https://gdz-ru.com/attachments/images/tasks/000/109/238/0002/5c373b8d07db3.jpg", "https://gdz-ru.com/attachments/images/tasks/000/109/238/0002/5c373b8d0840f.jpg"], "t62": ["https://gdz-ru.com/attachments/images/tasks/000/109/238/0002/5c373b8d08782.jpg", "https://gdz-ru.com/attachments/images/tasks/000/109/238/0002/5c373b8d08e73.jpg"], "t66": ["https://gdz-ru.com/attachments/images/tasks/000/109/238/0002/5c373b8d092ec.jpg"], "t69": ["https://gdz-ru.com/attachments/images/tasks/000/109/238/0002/5c373b8d09849.jpg"], "t71": ["https://gdz-ru.com/attachments/images/tasks/000/109/238/0002/5c373b8d09e24.jpg", "https://gdz-ru.com/attachments/images/tasks/000/109/238/0002/5c373b8d0a49a.jpg", "https://gdz-ru.com/attachments/images/tasks/000/109/238/0002/5c373b8d0aa6a.jpg", "https://gdz-ru.com/attachments/images/tasks/000/109/238/0002/5c373b8d0afc1.jpg"], "t72": ["https://gdz-ru.com/attachments/images/tasks/000/109/238/0002/5c373b8d0b351.jpg", "https://gdz-ru.com/attachments/images/tasks/000/109/238/0002/5c373b8d0b902.jpg", "https://gdz-ru.com/attachments/images/tasks/000/109/238/0002/5c373b8d0be92.jpg"], "t82": ["https://gdz-ru.com/attachments/images/tasks/000/109/238/0002/5c373b8d0c263.jpg"], "t87": ["https://gdz-ru.com/attachments/images/tasks/000/109/238/0002/5c373b8d0c6c0.jpg", "https://gdz-ru.com/attachments/images/tasks/000/109/238/0002/5c373b8d0cc4a.jpg"], "t99": ["https://gdz-ru.com/attachments/images/tasks/000/109/238/0002/5c373b8d0ced7.jpg", "https://gdz-ru.com/attachments/images/tasks/000/109/238/0002/5c373b8d0d3a2.jpg", "https://gdz-ru.com/attachments/images/tasks/000/109/238/0002/5c373b8d0d8b9.jpg"], "t100": ["https://gdz-ru.com/attachments/images/tasks/000/109/238/0002/5c373b8ce754d.jpg"], "t107": ["https://gdz-ru.com/attachments/images/tasks/000/109/238/0002/5c373b8ce7c8d.jpg", "https://gdz-ru.com/attachments/images/tasks/000/109/238/0002/5c373b8ce812b.jpg"], "t109": ["https://gdz-ru.com/attachments/images/tasks/000/109/238/0002/5c373b8ce84b6.jpg"], "t121": ["https://gdz-ru.com/attachments/images/tasks/000/109/238/0002/5c373b8ce8a16.jpg", "https://gdz-ru.com/attachments/images/tasks/000/109/238/0002/5c373b8ce8ee5.jpg", "https://gdz-ru.com/attachments/images/tasks/000/109/238/0002/5c373b8ce93ac.jpg"], "t123": ["https://gdz-ru.com/attachments/images/tasks/000/109/238/0002/5c373b8ce96b5.jpg", "https://gdz-ru.com/attachments/images/tasks/000/109/238/0002/5c373b8ce9b3f.jpg", "https://gdz-ru.com/attachments/images/tasks/000/109/238/0002/5c373b8cea00e.jpg", "https://gdz-ru.com/attachments/images/tasks/000/109/238/0002/5c373b8cea509.jpg"], "t127": ["https://gdz-ru.com/attachments/images/tasks/000/109/238/0002/5c373b8cea956.jpg", "https://gdz-ru.com/attachments/images/tasks/000/109/238/0002/5c373b8ceadb3.jpg"], "t135": ["https://gdz-ru.com/attachments/images/tasks/000/109/238/0002/5c373b8ceb5b2.jpg", "https://gdz-ru.com/attachments/images/tasks/000/109/238/0002/5c373b8ceba37.jpg", "https://gdz-ru.com/attachments/images/tasks/000/109/238/0002/5c373b8cebe85.jpg"], "t140": ["https://gdz-ru.com/attachments/images/tasks/000/109/238/0002/5c373b8cec4f7.jpg", "https://gdz-ru.com/attachments/images/tasks/000/109/238/0002/5c373b8cec97f.jpg"], "t148": ["https://gdz-ru.com/attachments/images/tasks/000/109/238/0002/5c373b8cecdaa.jpg", "https://gdz-ru.com/attachments/images/tasks/000/109/238/0002/5c373b8ced512.jpg"], "t158": ["https://gdz-ru.com/attachments/images/tasks/000/109/238/0002/5c373b8ced8be.jpg", "https://gdz-ru.com/attachments/images/tasks/000/109/238/0002/5c373b8cedd88.jpg"], "t166": ["https://gdz-ru.com/attachments/images/tasks/000/109/238/0002/5c373b8cee774.jpg", "https://gdz-ru.com/attachments/images/tasks/000/109/238/0002/5c373b8ceec06.jpg"], "t172": ["https://gdz-ru.com/attachments/images/tasks/000/109/238/0002/5c373b8ceeece.jpg"], "t173": ["https://gdz-ru.com/attachments/images/tasks/000/109/238/0002/5c373b8cef2c8.jpg", "https://gdz-ru.com/attachments/images/tasks/000/109/238/0002/5c373b8cef76e.jpg", "https://gdz-ru.com/attachments/images/tasks/000/109/238/0002/5c373b8cefc14.jpg"], "t182": ["https://gdz-ru.com/attachments/images/tasks/000/109/238/0002/5c373b8ceffc4.jpg"], "t189": ["https://gdz-ru.com/attachments/images/tasks/000/109/238/0002/5c373b8cf03a4.jpg"], "t196": ["https://gdz-ru.com/attachments/images/tasks/000/109/238/0002/5c373b8cf0b44.jpg", "https://gdz-ru.com/attachments/images/tasks/000/109/238/0002/5c373b8cf0fce.jpg"], "t201": ["https://gdz-ru.com/attachments/images/tasks/000/109/238/0002/5c373b8cf13ad.jpg", "https://gdz-ru.com/attachments/images/tasks/000/109/238/0002/5c373b8cf1851.jpg"], "t202": ["https://gdz-ru.com/attachments/images/tasks/000/109/238/0002/5c373b8cf1c8d.jpg", "https://gdz-ru.com/attachments/images/tasks/000/109/238/0002/5c373b8cf217b.jpg", "https://gdz-ru.com/attachments/images/tasks/000/109/238/0002/5c373b8cf26b0.jpg"], "t213": ["https://gdz-ru.com/attachments/images/tasks/000/109/238/0002/5c373b8cf32d7.jpg", "https://gdz-ru.com/attachments/images/tasks/000/109/238/0002/5c373b8cf379b.jpg", "https://gdz-ru.com/attachments/images/tasks/000/109/238/0002/5c373b8cf3c66.jpg", "https://gdz-ru.com/attachments/images/tasks/000/109/238/0002/5c373b8cf416e.jpg", "https://gdz-ru.com/attachments/images/tasks/000/109/238/0002/5c373b8d0043e.jpg", "https://gdz-ru.com/attachments/images/tasks/000/109/238/0002/5c373b8d0095a.jpg"], "t240": ["https://gdz-ru.com/attachments/images/tasks/000/109/238/0002/5c373b8d00cdd.jpg", "https://gdz-ru.com/attachments/images/tasks/000/109/238/0002/5c373b8d011a5.jpg"], "t257": ["https://gdz-ru.com/attachments/images/tasks/000/109/238/0002/5c373b8d01602.jpg", "https://gdz-ru.com/attachments/images/tasks/000/109/238/0002/5c373b8d01ad3.jpg"], "t268": ["https://gdz-ru.com/attachments/images/tasks/000/109/238/0002/5c373b8d01eac.jpg", "https://gdz-ru.com/attachments/images/tasks/000/109/238/0002/5c373b8d02349.jpg"], "t272": ["https://gdz-ru.com/attachments/images/tasks/000/109/238/0002/5c373b8d02765.jpg"], "t273": ["https://gdz-ru.com/attachments/images/tasks/000/109/238/0002/5c373b8d02bff.jpg", "https://gdz-ru.com/attachments/images/tasks/000/109/238/0002/5c373b8d030d2.jpg"], "t284": ["https://gdz-ru.com/attachments/images/tasks/000/109/238/0002/5c373b8d03e7c.jpg", "https://gdz-ru.com/attachments/images/tasks/000/109/238/0002/5c373b8d0433b.jpg", "https://gdz-ru.com/attachments/images/tasks/000/109/238/0002/5c373b8d04812.jpg"], "t2-5": ["https://gdz-ru.com/attachments/images/tasks/000/109/238/0002/5c373b8d20a76.jpg"]}

надо перебрать все "t***" и сделать из них
<a href="t***">***</a>
возможно ли это сделать, если возможно, то как?
  • Вопрос задан
  • 77 просмотров
Решения вопроса 1
1210mk2
@1210mk2
$s = '{"109238": [], "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"]}';

$obj = json_decode($s);

foreach($obj as $k => $a) {
	if ($k[0] !== 't') continue;
	foreach($a as $l) {	
		$res = '<a href="' . $k . '">' . $l . '</a>';
		var_dump ($res);
	}
}

пример
Ответ написан
Пригласить эксперта
Ответы на вопрос 2
@user49981
$json = '{"109238": [], "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": ["https://gdz-ru.com/attachments/images/tasks/000/109/238/0002/5c373b8cf079c.jpg"], "t21": ["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": ["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": ["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"], "t46": ["https://gdz-ru.com/attachments/images/tasks/000/109/238/0002/5c373b8d06830.jpg", "https://gdz-ru.com/attachments/images/tasks/000/109/238/0002/5c373b8d06e15.jpg"], "t49": ["https://gdz-ru.com/attachments/images/tasks/000/109/238/0002/5c373b8d0716b.jpg"], "t57": ["https://gdz-ru.com/attachments/images/tasks/000/109/238/0002/5c373b8d0774d.jpg", "https://gdz-ru.com/attachments/images/tasks/000/109/238/0002/5c373b8d07db3.jpg", "https://gdz-ru.com/attachments/images/tasks/000/109/238/0002/5c373b8d0840f.jpg"], "t62": ["https://gdz-ru.com/attachments/images/tasks/000/109/238/0002/5c373b8d08782.jpg", "https://gdz-ru.com/attachments/images/tasks/000/109/238/0002/5c373b8d08e73.jpg"], "t66": ["https://gdz-ru.com/attachments/images/tasks/000/109/238/0002/5c373b8d092ec.jpg"], "t69": ["https://gdz-ru.com/attachments/images/tasks/000/109/238/0002/5c373b8d09849.jpg"], "t71": ["https://gdz-ru.com/attachments/images/tasks/000/109/238/0002/5c373b8d09e24.jpg", "https://gdz-ru.com/attachments/images/tasks/000/109/238/0002/5c373b8d0a49a.jpg", "https://gdz-ru.com/attachments/images/tasks/000/109/238/0002/5c373b8d0aa6a.jpg", "https://gdz-ru.com/attachments/images/tasks/000/109/238/0002/5c373b8d0afc1.jpg"], "t72": ["https://gdz-ru.com/attachments/images/tasks/000/109/238/0002/5c373b8d0b351.jpg", "https://gdz-ru.com/attachments/images/tasks/000/109/238/0002/5c373b8d0b902.jpg", "https://gdz-ru.com/attachments/images/tasks/000/109/238/0002/5c373b8d0be92.jpg"], "t82": ["https://gdz-ru.com/attachments/images/tasks/000/109/238/0002/5c373b8d0c263.jpg"], "t87": ["https://gdz-ru.com/attachments/images/tasks/000/109/238/0002/5c373b8d0c6c0.jpg", "https://gdz-ru.com/attachments/images/tasks/000/109/238/0002/5c373b8d0cc4a.jpg"], "t99": ["https://gdz-ru.com/attachments/images/tasks/000/109/238/0002/5c373b8d0ced7.jpg", "https://gdz-ru.com/attachments/images/tasks/000/109/238/0002/5c373b8d0d3a2.jpg", "https://gdz-ru.com/attachments/images/tasks/000/109/238/0002/5c373b8d0d8b9.jpg"], "t100": ["https://gdz-ru.com/attachments/images/tasks/000/109/238/0002/5c373b8ce754d.jpg"], "t107": ["https://gdz-ru.com/attachments/images/tasks/000/109/238/0002/5c373b8ce7c8d.jpg", "https://gdz-ru.com/attachments/images/tasks/000/109/238/0002/5c373b8ce812b.jpg"], "t109": ["https://gdz-ru.com/attachments/images/tasks/000/109/238/0002/5c373b8ce84b6.jpg"], "t121": ["https://gdz-ru.com/attachments/images/tasks/000/109/238/0002/5c373b8ce8a16.jpg", "https://gdz-ru.com/attachments/images/tasks/000/109/238/0002/5c373b8ce8ee5.jpg", "https://gdz-ru.com/attachments/images/tasks/000/109/238/0002/5c373b8ce93ac.jpg"], "t123": ["https://gdz-ru.com/attachments/images/tasks/000/109/238/0002/5c373b8ce96b5.jpg", "https://gdz-ru.com/attachments/images/tasks/000/109/238/0002/5c373b8ce9b3f.jpg", "https://gdz-ru.com/attachments/images/tasks/000/109/238/0002/5c373b8cea00e.jpg", "https://gdz-ru.com/attachments/images/tasks/000/109/238/0002/5c373b8cea509.jpg"], "t127": ["https://gdz-ru.com/attachments/images/tasks/000/109/238/0002/5c373b8cea956.jpg", "https://gdz-ru.com/attachments/images/tasks/000/109/238/0002/5c373b8ceadb3.jpg"], "t135": ["https://gdz-ru.com/attachments/images/tasks/000/109/238/0002/5c373b8ceb5b2.jpg", "https://gdz-ru.com/attachments/images/tasks/000/109/238/0002/5c373b8ceba37.jpg", "https://gdz-ru.com/attachments/images/tasks/000/109/238/0002/5c373b8cebe85.jpg"], "t140": ["https://gdz-ru.com/attachments/images/tasks/000/109/238/0002/5c373b8cec4f7.jpg", "https://gdz-ru.com/attachments/images/tasks/000/109/238/0002/5c373b8cec97f.jpg"], "t148": ["https://gdz-ru.com/attachments/images/tasks/000/109/238/0002/5c373b8cecdaa.jpg", "https://gdz-ru.com/attachments/images/tasks/000/109/238/0002/5c373b8ced512.jpg"], "t158": ["https://gdz-ru.com/attachments/images/tasks/000/109/238/0002/5c373b8ced8be.jpg", "https://gdz-ru.com/attachments/images/tasks/000/109/238/0002/5c373b8cedd88.jpg"], "t166": ["https://gdz-ru.com/attachments/images/tasks/000/109/238/0002/5c373b8cee774.jpg", "https://gdz-ru.com/attachments/images/tasks/000/109/238/0002/5c373b8ceec06.jpg"], "t172": ["https://gdz-ru.com/attachments/images/tasks/000/109/238/0002/5c373b8ceeece.jpg"], "t173": ["https://gdz-ru.com/attachments/images/tasks/000/109/238/0002/5c373b8cef2c8.jpg", "https://gdz-ru.com/attachments/images/tasks/000/109/238/0002/5c373b8cef76e.jpg", "https://gdz-ru.com/attachments/images/tasks/000/109/238/0002/5c373b8cefc14.jpg"], "t182": ["https://gdz-ru.com/attachments/images/tasks/000/109/238/0002/5c373b8ceffc4.jpg"], "t189": ["https://gdz-ru.com/attachments/images/tasks/000/109/238/0002/5c373b8cf03a4.jpg"], "t196": ["https://gdz-ru.com/attachments/images/tasks/000/109/238/0002/5c373b8cf0b44.jpg", "https://gdz-ru.com/attachments/images/tasks/000/109/238/0002/5c373b8cf0fce.jpg"], "t201": ["https://gdz-ru.com/attachments/images/tasks/000/109/238/0002/5c373b8cf13ad.jpg", "https://gdz-ru.com/attachments/images/tasks/000/109/238/0002/5c373b8cf1851.jpg"], "t202": ["https://gdz-ru.com/attachments/images/tasks/000/109/238/0002/5c373b8cf1c8d.jpg", "https://gdz-ru.com/attachments/images/tasks/000/109/238/0002/5c373b8cf217b.jpg", "https://gdz-ru.com/attachments/images/tasks/000/109/238/0002/5c373b8cf26b0.jpg"], "t213": ["https://gdz-ru.com/attachments/images/tasks/000/109/238/0002/5c373b8cf32d7.jpg", "https://gdz-ru.com/attachments/images/tasks/000/109/238/0002/5c373b8cf379b.jpg", "https://gdz-ru.com/attachments/images/tasks/000/109/238/0002/5c373b8cf3c66.jpg", "https://gdz-ru.com/attachments/images/tasks/000/109/238/0002/5c373b8cf416e.jpg", "https://gdz-ru.com/attachments/images/tasks/000/109/238/0002/5c373b8d0043e.jpg", "https://gdz-ru.com/attachments/images/tasks/000/109/238/0002/5c373b8d0095a.jpg"], "t240": ["https://gdz-ru.com/attachments/images/tasks/000/109/238/0002/5c373b8d00cdd.jpg", "https://gdz-ru.com/attachments/images/tasks/000/109/238/0002/5c373b8d011a5.jpg"], "t257": ["https://gdz-ru.com/attachments/images/tasks/000/109/238/0002/5c373b8d01602.jpg", "https://gdz-ru.com/attachments/images/tasks/000/109/238/0002/5c373b8d01ad3.jpg"], "t268": ["https://gdz-ru.com/attachments/images/tasks/000/109/238/0002/5c373b8d01eac.jpg", "https://gdz-ru.com/attachments/images/tasks/000/109/238/0002/5c373b8d02349.jpg"], "t272": ["https://gdz-ru.com/attachments/images/tasks/000/109/238/0002/5c373b8d02765.jpg"], "t273": ["https://gdz-ru.com/attachments/images/tasks/000/109/238/0002/5c373b8d02bff.jpg", "https://gdz-ru.com/attachments/images/tasks/000/109/238/0002/5c373b8d030d2.jpg"], "t284": ["https://gdz-ru.com/attachments/images/tasks/000/109/238/0002/5c373b8d03e7c.jpg", "https://gdz-ru.com/attachments/images/tasks/000/109/238/0002/5c373b8d0433b.jpg", "https://gdz-ru.com/attachments/images/tasks/000/109/238/0002/5c373b8d04812.jpg"], "t2-5": ["https://gdz-ru.com/attachments/images/tasks/000/109/238/0002/5c373b8d20a76.jpg"]}';
$array = json_decode($json);
$links = [];

foreach ($array as $key => $ls) {
    foreach($ls as $link) {
        $links[] = "<a href={$link}>{$key}</a>";
    }
}

print_r($links);
Ответ написан
Ваш ответ на вопрос

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

Войти через центр авторизации
Похожие вопросы
21 авг. 2019, в 00:43
500 руб./за проект
21 авг. 2019, в 00:14
1000 руб./за проект