Answer the question
In order to leave comments, you need to log in
How to find object without JSON decode PHP key?
Welcome all.
Get JSON file, decode it
{
"response": [{
"id": "29654",
"user": "USER",
},
......
]}
$array_decode = json_decode($url,true);
$array_decode['response'][идентф_ключа]['user'];
Answer the question
In order to leave comments, you need to log in
Rebuild the users array:
$out_users = [];
foreach($array_decode['response'] as $user)
$out_users[$user['id']]['user'] = $user['user'];
$out_users = [];
foreach($array_decode['response'] as &$user) // обратите внимание на доступ по ссылке & к элементу массива
{
$out_users[$user['id']]['user'] = $user['user'];
unset($user); //удаляем элемент из массива $array_decode['response'], чтобы не росло использование памяти.
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question