1

This is my response code:

'[{"id":"153","title":"xyz","description":"abc"}, 
{"id":"154","title":"xyy","description":"abb"}]' 

in this code i need to get values from id=154 only and i need only that particular array values only using php code?

if I have variable $a=154; it will get that particular id and title and description values only. if I have variable $a=153; it will get that particular id and title and description values only.

1

2 Answers 2

1

Using Javascript :

json[0].id

Using PHP :

$json  = json_decode($your_json_str);
echo $json[0]->id;

You can get the value 153.

$a = 153;

foreach($json as $key => $element){
if($element->id == $a){
    echo $element->id,"<br>";
    echo $element->title,"<br>";
    echo $element->description,"<br>";
   }
}
Sign up to request clarification or add additional context in comments.

Comments

0
$jsonStr  = '[
              {"id":"153","title":"xyz","description":"abc"}, 
              {"id":"154","title":"xyy","description":"abb"}
             ]';
$arrJson  = json_decode($jsonStr);
$keyVal   = 154;
foreach($arrJson as $key => $val){
if($val->id == $keyVal){
    echo $val->id;//Id
    echo $val->title;//Title
    echo $val->description;//Descrption
   }
}

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.