I have this recursive function that seems to get what I am looking for when I echo from the function but I don't understand how to save the results from all the loops and return them all as an array. I tried a few ways which I removed from the code to clean it up but none of them even came close to working.
So how would I get all the results back out of this function?
Thank you-
Danny
function role_recursive($user_role_data)
{
global $sql;
if(is_array($user_role_data))
{
foreach($user_role_data as $row)
{
echo '<p>array sent into function<br>';
print_r($row);
echo '</p>';
if(is_array($row))
{
$sql->go("SELECT rid,parent FROM roles WHERE rid = '{$row['rid']}' LIMIT 1");
$role_data = $sql->fetchArray();
echo'<p>check to see if array has parent<br>';
print_r($role_data);
echo'</p>';
if($role_data['parent']==0)
{
echo $role_data['rid'].' no parent<hr>';
} else
{
echo $role_data['rid'].' has parent '.$role_data['parent'].'<hr>';
$sql->go("SELECT * FROM roles_permissions WHERE rid = '{$role_data['parent']}' LIMIT 1");
$new_permissions[] = $sql->fetchArray();
$out = role_recursive($new_permissions);
}
}
}
}
}
I get this output that looks good, it got the parents within parents so that part is working it seems.
array sent into function
Array ( [uid] => 1 [rid] => 1 [perm] => 5,6,7,8, )
check to see if array has parent
Array ( [0] => 1 [rid] => 1 [1] => 0 [parent] => 0 )
1 no parent
array sent into function
Array ( [uid] => 1 [rid] => 6 [perm] => 3,4, )
check to see if array has parent
Array ( [0] => 6 [rid] => 6 [1] => 0 [parent] => 0 )
6 no parent
array sent into function
Array ( [uid] => 1 [rid] => 9 [perm] => 1, )
check to see if array has parent
Array ( [0] => 9 [rid] => 9 [1] => 8 [parent] => 8 )
9 has parent 8
array sent into function
Array ( [0] => 8 [rid] => 8 [1] => 7,8, [perm] => 7,8, )
check to see if array has parent
Array ( [0] => 8 [rid] => 8 [1] => 7 [parent] => 7 )
8 has parent 7
array sent into function
Array ( [0] => 7 [rid] => 7 [1] => 5,4,3,6, [perm] => 5,4,3,6, )
check to see if array has parent
Array ( [0] => 7 [rid] => 7 [1] => 0 [parent] => 0 )
7 no parent