我有一个函数,我可以使用echo获取所有正确的值,但是当我无法弄清楚如何返回整个数组。有人可以帮我解决所有的儿童用户吗?
$useridarray[] = $userid;
getchildren($useridarray, $useridarray);
function getchildren($array, $totalarray)
{
foreach($array as $arr)
{
$db_name = "dbname";
$connection = @mysql_connect("localhost", "username", "password") or die(mysql_error());
$db = @mysql_select_db($db_name, $connection) or die(mysql_error());
$sql = "
select *
from users
where creator = '$arr'
";
$result = @mysql_query($sql, $connection) or die(mysql_error());
while($row = mysql_fetch_array($result))
{
$newchildren[] = $row['id'];
$totalarray[] = $row['id'];
//echo $row['id'] . ' ';
}
mysql_close();
getchildren($newchildren, $totalarray);
}
}
答案 0 :(得分:1)
function getchildren($array, &$totalarray)
^
用法:
$useridarray[] = $userid;
getchildren($useridarray, $useridarray);
var_dump($useridarray); # your result
答案 1 :(得分:0)
您需要在
之前添加返回 mysql_close();
return getchildren($newchildren, $totalarray);
答案 2 :(得分:0)
我不熟悉PHP语法,但您可能希望实现“停止标准”以返回结果。所以在你的实例中,你似乎想要一些东西,其中getChildren返回localResults +递归的getChildren结果,这些结果在你的foreach循环中以递增的方式总计。