0

How to convert this array into a string in php

been practicing some API's now encountered the TMDB API and i don't know how to convert genre into string.. consider this json data; below {"adult":false,"backdrop_path":"/VuukZLgaCrho2Ar8Scl9HtV3yD.jpg","belongs_to_collection":null,"budget":116000000,"genres":[{"id":878,"name":"Science Fiction"},{"id":28,"name":"Action"},{"id":80,"name":"Crime"},{"id":28,"name":"Action"},{"id":27,"name":"Horror"}],"homepage":"http://www.venom.movie/site/","id":335983,"imdb_id":"tt1270797","original_language":"en","original_title":"Venom","overview":"When Eddie Brock acquires the powers of a symbiote, he will have to release his alter-ego \"Venom\" to save his life.","popularity":376.826,"poster_path":"/2uNW4WbgBXL25BAbXGLnLqX71Sw.jpg","production_companies":[{"id":5,"logo_path":"/71BqEFAF4V3qjjMPCpLuyJFB9A.png","name":"Columbia Pictures","origin_country":"US"},{"id":7505,"logo_path":"/837VMM4wOkODc1idNxGT0KQJlej.png","name":"Marvel Entertainment","origin_country":"US"},{"id":34,"logo_path":"/GagSvqWlyPdkFHMfQ3pNq6ix9P.png","name":"Sony Pictures","origin_country":"US"},{"id":75841,"logo_path":null,"name":"A.A. Productions Co.","origin_country":""}],"production_countries":[{"iso_3166_1":"AS","name":"American Samoa"},{"iso_3166_1":"AD","name":"Andorra"},{"iso_3166_1":"AO","name":"Angola"}],"release_date":"2018-10-03","revenue":205230000,"runtime":112,"spoken_languages":[{"iso_639_1":"en","name":"English"}],"status":"Released","tagline":"The world has enough Superheroes.","title":"Venom","video":false,"vote_average":6.6,"vote_count":1625} i used php with $url = "https://api.themoviedb.org/3/movie/335983?api_key=HERE_IS_API_KEY" $fgc = file_get_contents($url); $json = json_decode($fgc, true); now if i say when i say.. $adult = $json['adult']; if (adult == true) { echo "8+"; }..... i get the results or eif i say $title = $json['title']; when i echo $title i get the movie title.. now something i different with the the genres, production_companies and the like.. so how do i convert that type of array to

27th Oct 2018, 9:11 PM
Yohanna Wilbertson
Yohanna Wilbertson - avatar
2 Answers
+ 4
Loop them $genres = $json[’genres’]; for($a = 0; $a < count($genres); $a++) { $genre = $genres[$a]; echo ”genres: ”; foreach($genre as $key => $value) { echo $key . ”: ” . $value; }; };
27th Oct 2018, 10:04 PM
Toni Isotalo
Toni Isotalo - avatar
+ 2
looks like this needs to be broken down into smaller questions and fragments of code dealt with...
27th Oct 2018, 9:37 PM
BroFar
BroFar - avatar