1

I am wondering how I would list the json values for each part of the list

my php code

$uri = "https://yt-dl-server.herokuapp.com/api/info?url=https://www.youtube.com/watch?v=$id";

$ci = curl_init();
curl_setopt( $ci, CURLOPT_URL, $uri );
curl_setopt( $ci, CURLOPT_RETURNTRANSFER, 1 );
$channelOBJE = json_decode( curl_exec( $ci ) );

$format_note = $channelOBJE->info->formats[20]->format_note; 
$videourl = $channelOBJE->info->formats[20]->url; 
$audiourl = $channelOBJE->info->formats[1]->url; 
echo $format_note;
echo "<br>";

Following that code I want to get the $format_note for every formats[] but I don't want to have to list the number value of it. Thanks!

3
  • 1
    Did you try with looping on $channelOBJE->info? Commented Nov 17, 2018 at 6:32
  • You should try to be clearer in your terminology and question; neither the JSON data format nor PHP natively have the concept of lists. cURL is for making remote requests to send or receive data, it doesn't have the concept of foreach. It's unclear whether you are trying to iterate over multiple results from a single cURL request or whether you want to avoid needing to make multiple requests to obtain all the data you need. Commented Nov 17, 2018 at 10:23
  • Possible duplicate of How to loop through array of multiple arrays in php Commented Nov 17, 2018 at 14:49

1 Answer 1

0

use foreach() to loop the formats.

foreach($channelOBJE->info->formats as $format){
    var_dump($format->format_note);
}
Sign up to request clarification or add additional context in comments.

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.