How to access specific JSON object value using PHP

1 Answer

0 votes
$JSON = '{"Website": [{"url": "https://www.collectivesolver.com/", "title": "Collective Solver"},
                     {"url": "https://www.collectivesolver.com/32116/how-to-split-a-string-in-c", "title": "How to split a string in C - Collective Solver"}]}';

$jsonDecod = json_decode($JSON, true);

$URL = $jsonDecod['Website'][0]['url'];
$title = $jsonDecod['Website'][0]['title'];

echo $URL . "\n";
echo $title . "\n";


$URL = $jsonDecod['Website'][1]['url'];
$title = $jsonDecod['Website'][1]['title'];

echo $URL . "\n";
echo $title . "\n";




/*
run:

https://www.collectivesolver.com/
Collective Solver
https://www.collectivesolver.com/32116/how-to-split-a-string-in-c
How to split a string in C - Collective Solver

*/

 



answered Jun 28, 2020 by avibootz

Related questions

3 answers 279 views
3 answers 233 views
1 answer 177 views
177 views asked Jan 29, 2022 by avibootz
1 answer 157 views
157 views asked Feb 16, 2021 by avibootz
1 answer 235 views
3 answers 323 views
...