Hi! Could we please enable some services and cookies to improve your experience and our website?

PHPize Online / SQLize Online  /  SQLtest Online

A A A
Login    Share code      Blog   FAQ

Online Sandbox for SQL and PHP: Write, Run, Test, and Share SQL Queries and PHP Code

Copy Format Clear

Stuck with a problem? Got Error? Ask AI support!

Copy Clear
Copy Format Clear
<?php function categories_list($mysqli, $id = 0, $list = []) { $stmt = $mysqli->prepare("SELECT * FROM categories WHERE parent = ?"); $stmt->bind_param('i', $id); $stmt->execute(); foreach ($stmt->get_result() as $value) { $list[] = $value['id']; //var_export($value); array_push($list, ...categories_list($mysqli, $value['id'], $list)); } return array_unique($list); } var_export(categories_list($mysqli, 0));
Copy Clear