0

I am using the BandsInTown API, and I'm trying to list all the event titles for a band. The code below works for the first title, but I need to look through all of them. I tried a foreach loop I found on here, but did have any luck. How do I show all the event titles for a particular band? I have been looking at previous questions like this one.

$json = file_get_contents("http://api.bandsintown.com/artists/Skrillex/events.json?api_version=2.0&app_id=MYID");
$data = json_decode($json);
echo $data[0]->title;

// I tried this, but it didn't work
foreach($data->title as $title){
   echo $title;
}        

3 Answers 3

3

I think you might be look for something like

foreach($data as $datum){
    echo $datum->title;
}
Sign up to request clarification or add additional context in comments.

Comments

2

Try this.,

foreach($data as $Events){
    echo $Events->title."<br>"; 
}

Comments

0

Try..

foreach($data as $item){
   echo $item->title; 
}

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.