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 5.0.0 - 5.0.5, 5.1.0 - 5.1.6, 5.2.0 - 5.2.17, 5.3.0 - 5.3.29, 5.4.0 - 5.4.45, 5.5.0 - 5.5.38, 5.6.0 - 5.6.38, 7.0.0 - 7.0.33, 7.1.0 - 7.1.25, 7.2.0 - 7.2.33, 7.3.0 - 7.3.33, 7.4.0 - 7.4.33, 8.0.0 - 8.0.30, 8.1.0 - 8.1.28, 8.2.0 - 8.2.18, 8.3.0 - 8.3.7
Output for 4.4.2 - 4.4.9
Parse error: syntax error, unexpected '=', expecting ')' in /in/b4Bp8 on line 27
Process exited with code 255.
Output for 4.3.0 - 4.3.1, 4.3.5 - 4.3.11, 4.4.0 - 4.4.1
Parse error: parse error, unexpected '=', expecting ')' in /in/b4Bp8 on line 27
Process exited with code 255.
Output for 4.3.2 - 4.3.4
Parse error: parse error, expecting `')'' in /in/b4Bp8 on line 27
Process exited with code 255.

preferences:
249.56 ms | 401 KiB | 423 Q