Welcome to collectivesolver - Programming & Software Q&A. A website you can trust. I check, compile and run every program. Contact me at: aviboots(AT)netvision.net.il

Hostgator - Save 50% Off Your New Optimized WordPress Hosting With Coupon: WDA50

BlueHost Web Hosting

Ecommerce Software - Best Ecommerce Platform Made for You - Free Trial

Dedicated Hosting Superb Internet

simplilearn big data and analytics

Ecommerce Software - Best Ecommerce Platform Made for You - Free Trial

Buy Cool Shirts

getflywheel wordpress hosting


Distribute your Resume to 500+ Job Boards & Recruiters


6,300 questions

8,938 answers

573 users

How to decode a JSON string into an array in PHP

Ecommerce Software - Best Ecommerce Platform Made for You - Free Trial


13 views
asked Sep 3 by avibootz

5 Answers

0 votes
$json_string = '["name", "Tim", "age", 51, "profession", "Programmer"]';
$array = json_decode($json_string);

printf('%s: %s<br />', $array[0], $array[1]);
printf('%s: %s<br />', $array[2], $array[3]);
printf('%s: %s<br />', $array[4], $array[5]);


/*
run: 
 
name: Tim
age: 51
profession: Programmer
 
*/

 




answered Sep 3 by avibootz
0 votes
$json_string = '["Tim", 51, "Programmer"]';
$array = json_decode($json_string);

printf('%s %s %s<br />', $array[0], $array[1], $array[2]);


/*
run: 
 
Tim 51 Programmer
 
*/

 




answered Sep 3 by avibootz
0 votes
$json_string = '["Tim", 51, "Programmer", ["PHP", "JAVA"]]';
$array = json_decode($json_string);

printf('%s %s %s %s %s<br />', $array[0], $array[1], $array[2], $array[3][0], $array[3][1]);


/*
run: 
 
Tim 51 Programmer PHP JAVA
 
*/

 




answered Sep 3 by avibootz
0 votes
$json_string = '["Tim", 51, "Programmer", ["PHP", "JAVA"]]';
$array = json_decode($json_string);
                      
echo "<pre>";
var_dump($array);
echo "</pre>";

/*
run: 
 
array(4) {
  [0]=>
  string(3) "Tim"
  [1]=>
  int(51)
  [2]=>
  string(10) "Programmer"
  [3]=>
  array(2) {
    [0]=>
    string(3) "PHP"
    [1]=>
    string(4) "JAVA"
  }
}
 
*/

 




answered Sep 3 by avibootz
0 votes
$json_string = '{"name": "Tim", "profession": "Programmer", "language": ["PHP", "JAVA"]}';
$array = json_decode($json_string, true);
                      
echo "<pre>";
var_dump($array);
echo "</pre>";

/*
run: 
 
array(3) {
  ["name"]=>
  string(3) "Tim"
  ["profession"]=>
  string(10) "Programmer"
  ["language"]=>
  array(2) {
    [0]=>
    string(3) "PHP"
    [1]=>
    string(4) "JAVA"
  }
}
 
*/

 




answered Sep 3 by avibootz
...