Skip to content

Instantly share code, notes, and snippets.

@nickyleach
Created December 10, 2010 01:43
Show Gist options
  • Save nickyleach/735630 to your computer and use it in GitHub Desktop.
Save nickyleach/735630 to your computer and use it in GitHub Desktop.
Simple example of parsing Yelps category structure to dereference an ID
<?
function find_category($id, $categories){
if(!count($categories)) return false;
foreach($categories as $set){
if($set['id'] == $id) return $set['t'];
$category = find_category($id, $set['c']);
if($category) break;
}
return $category;
}
$category = find_category('-Z6XiTi5GStH07pq0NmlZg', json_decode(file_get_contents('http://www.yelp.com/category_tree_json'), true));
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment