0

hi want to loop through json below how can i do this using php

{
values: [
{
   nameValuePairs: {
   address: "0111",
   body: "Transaction cost, Ksh28.00.",
   date: "1571473093291",
}
},
{
   nameValuePairs: {
   address: "0101",
   body: "Transaction cost, Ksh0.00.",
   date: "1498823347530",
  }
  },
]
}

need the values of address,body and date in a foreach loop thanks in advance

0

1 Answer 1

0

You can convert json to array by using json_decode and loop through the array

 $a =  json_decode($json, true);

Use Loop

 foreach($a['values'] as $v){
  echo $v['nameValuePairs']['address']."\n";
  echo $v['nameValuePairs']['body']."\n";
  echo $v['nameValuePairs']['date']."\n";
 }

See demo here : https://3v4l.org/QC06g

Sign up to request clarification or add additional context in comments.

5 Comments

i alredy tried this $a = json_decode($json, true); foreach($a as $row){ $row["address"] } not getting result
@Fredmax you should have valid json format, check the link
Hi @Rakesh thank you for your response, i was able to get result as per your link 3v4l.org/IdrZk, kindly how do i loop through to get values of address,body and date i tried foreach($new_array as $row ) { echo $row["address"]; }
@Fredmax here 3v4l.org/QC06g, all the information iteration
@RakeshJakhar please edit your answer to include what you have in the comments.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.