3v4l.org

run code in 300+ PHP versions simultaneously
<?php // I have a table `categoreis` to store products' categories information // it use categories_id and parent_id to identify the level relationship between those categories // now I want a function(tep_get_leaf_categories() below) to get all leaf categories for a passed in category_id // say tep_get_leaf_categories(360) will get all leaf categories id as an array of category 360 // this function get all subcategories, or child-categories for $category_id function tep_get_subcategories($category_id) { $subcategories_raw = tep_db_query('SELECT ca.categories_id FROM categories ca LEFT JOIN categoreis cb ON ca.parent_id = cb.categories_id WHERE cb.categoreis_id = ' . (int) $category_id); $subcategories = array(); if (mysql_num_rows($subcategories_raw) >= 1) { while ($row = mysql_fetch_assoc($subcategories_raw)) { $category_id = $row['categories_id']; $subcategories[] = $category_id; } } return $subcategories; } // this is the function that I'm working on, to get the leaf category of $category_id function tep_get_leaf_categories($category_id, &$result = array()) { $sub_categories = tep_get_subcategories($category_id); // no sub categories found:return self as result if (count($sub_categories) === 0) { $result[] = $category_id; } else { foreach ($sub_categories as $category_id) { tep_get_leaf_categories($category_id, $result); } } return $result; }
Output for git.master, git.master_jit, rfc.property-hooks

This tab shows result from various feature-branches currently under review by the php developers. Contact me to have additional branches featured.

Active branches

Archived branches

Once feature-branches are merged or declined, they are no longer available. Their functionality (when merged) can be viewed from the main output page


preferences:
40.96 ms | 401 KiB | 8 Q