I have been working on a recursive function to get breadcrumb information from subcategory to category for several levels. I am able to retrieve this info, but once I return an array of arrays with this function, I can't do print_r to see contents.
Let me show you the code before I rant on:
function breadcrumb_array ($id, $breadcrumb = array()) {
$cat_info = get_subcat_data($id);
if ($cat_info["parent_id"]>0) {
$breadcrumb[] = $cat_info;
breadcrumb_array($cat_info["parent_id"], $breadcrumb);
} else {
echo "About to return the value...";
//print_r(array_reverse($breadcrumb));
return array_reverse($breadcrumb);
}
}
$breadcrumb = breadcrumb_array(8);
print_r($breadcrumb);
If I uncomment print_r(...) within the function, it will bring up the array of arrays properly:
( [0] => Array
( [id] => 3
[nombre] => Muebles
[parent_id] => 1
[parent_urlname] =>
[parent_nombre] => Productos
)
[1] => Array
( [id] => 6
[nombre] => Sillas
[parent_id] => 3
[parent_urlname] =>
[parent_nombre] => Muebles
)
[2] => Array
(
[id] => 8
[nombre] => Sillas de cocina
[parent_id] => 6
[parent_urlname] =>
[parent_nombre] => Sillas
)
)
So when I do print_r at the very end, after calling the function, I expect to print the same array of arrays. But I get nothing. I think I have tested everything that can go wrong within the function. I really can't see what goes wrong when printing the returned value. Can you help?
PS: In case anyone needs it, the get_subcat_id() function goes as follows:
//Retrieves mroe info about a certain categories and its parent
function get_subcat_data ($id) {
global $connection;
$query = "SELECT tblCategoria.id, tblCategoria.nombre, tblCategoria.parent_id, tblParents.urlname AS parent_urlname, tblParents.nombre AS parent_nombre
FROM tblCategoria JOIN tblCategoria AS tblParents ON tblCategoria.parent_id = tblParents.id
WHERE tblCategoria.id = {$id}
LIMIT 1";
$cats1 = mysql_query($query, $connection);
confirm_query($cats1);
$cats1 = mysql_fetch_assoc($cats1);
return $cats1;
}