Need help with for loop

Hi

I am trying to display all elements of an array by returning it in the function. I understand you can not return multiple values in PHP and so I probably need to use a loop. i would appreciate your guidance.

Below is my function . It uses Yelp API to display cafes nearby.

function cafe_display() {

// 1

$data = get_cafe_data(); 



// 2

if (!$data) {

  return "no data";

}



// 3

$json = json_decode($data, true);

$businesses = $json["businesses"];



// 4

$cafes = array($businesses[0]["name"], $businesses[0]["image_url"]); 


return $cafes[0];

}

I am looking to display * name, url, rating and a bunch of other info for each cafe.

Thank you

My recommendation would be to create a business class, then you look through the json returned and parse it out creating an array of businesses to more easily display what you want.

Sponsor our Newsletter | Privacy Policy | Terms of Service