mikka23 Posted February 9, 2010 Share Posted February 9, 2010 Hi I am trying to pull some information from the themeforest API. I implemented it fine when the information was under just one array but in this case it seems to be under popular array and then items-last-week array. This is the structure of the API: http://marketplace.envato.com/api/edge/popular:themeforest.xml Here is my code, I am trying to get the information for items-last-week. <?php $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, 'http://marketplace.envato.com/api/edge/popular:themeforest.json'); curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 5); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); $ch_data = curl_exec($ch); curl_close($ch); if(!empty($ch_data)) { $json_data = json_decode($ch_data, true); $data_count = count($json_data['popular']) -1; for($i = 0; $i <= $data_count; $i++) { echo '<li><a href="',$json_data['popular'][$i]['url'],'"><img src="',$json_data['popular'][$i]['thumbnail'],'" alt="" height="80px" width="80px"/></a><p><a href="',$json_data['popular'][$i]['url'],'">',$json_data['popular'][$i]['item'],'</a><br>$',$json_data['popular'][$i]['cost'],'</p></li>'; } } else { echo 'Sorry, but there was a problem connecting to the API.'; } ?> Any ideas? Help is greatly appreciated. I though I could just replace ,$json_data['popular'][$i]['url'] with ,$json_data['popular'][$i]['items-last-week']['url'] but obviously not Link to comment https://forums.phpfreaks.com/topic/191485-trouble-with-arrays-reckon-its-very-simple/ Share on other sites More sharing options...
WolfRage Posted February 9, 2010 Share Posted February 9, 2010 Going to need a var_dump() of the array then you should be able to see it's exact structure. Then you can decide how to loop through it. If var_dump is not deep enough you can create a function with a foreach in it that will loop deeper and deeper if the value is an array. If you need more information on how to do just that let me know. But the quick of it is that the function in the foreach finds an array as the value and then calls it's self to go deeper. Link to comment https://forums.phpfreaks.com/topic/191485-trouble-with-arrays-reckon-its-very-simple/#findComment-1009434 Share on other sites More sharing options...
jl5501 Posted February 9, 2010 Share Posted February 9, 2010 both var_dump() and print_r() will recurse to the lowest level of an array so you get to see all levels Link to comment https://forums.phpfreaks.com/topic/191485-trouble-with-arrays-reckon-its-very-simple/#findComment-1009439 Share on other sites More sharing options...
mikka23 Posted February 9, 2010 Author Share Posted February 9, 2010 Here is a var dump of json_decode($ch_data, true). http://freecss.info/colorful/wp-content/themes/FreeCSS/popular.php I have done that already. My problem is I dont know how to select the info i want even if I know the structure. Link to comment https://forums.phpfreaks.com/topic/191485-trouble-with-arrays-reckon-its-very-simple/#findComment-1009441 Share on other sites More sharing options...
WolfRage Posted February 10, 2010 Share Posted February 10, 2010 jl5501, your comment is not always true that depends on PHP's setting for that server. If the server has xdebug installed then you will have to modify the ini to say "xdebug.var_display_max_depth=n" or else you will need to use a function in order to loop deep enough. That is the reason that I presented that option. Mikka23, sorry but I can not see that page on my work computer, you will have to post the out put in a code box for me. Link to comment https://forums.phpfreaks.com/topic/191485-trouble-with-arrays-reckon-its-very-simple/#findComment-1009949 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.