-2

I have a json response like following

{"name":['abc','def','ghi','jkl']}

How can i extract each of those names in php?

expected out put :

abc
def
ghi
jkl
jomin v george
  • 1,299
  • 11
  • 26

2 Answers2

1

Use json_decode and

See this link
function.json-decode.php

   $jsons=array('name'=>array("abc","def","ghi","jkl"));  
   foreach($jsons as $json ){
        foreach($json as $val){
            echo $val  .'<br>';
        }
    }
paranoid
  • 6,799
  • 19
  • 49
  • 86
0

Use like this

<?php
 $var = '{"name":["abc","xyz"]}';// here will be your response
  $arr = json_decode($var);
 foreach($arr->name as  $key=>$value)
 echo $value."<br/>";
 ?>
Drone
  • 1,114
  • 1
  • 12
  • 31