试图在函数中返回一个数组。没有好运...返回PHP中数组的问题
(flag_friend_get_friends()方法返回包含数组的对象列表的功能)
因此,没有一个功能,这个工程:
<?php
$users_friends = flag_friend_get_friends($user->uid);
foreach ($users_friends as $id => $value) {
$users_friends_ids[] = $id;
}
$test = $users_friends_ids;
print $test[0];
?>
如果我尝试和包装它的功能,它不起作用(没有打印)...:
<?php
function myfunc() {
$users_friends = flag_friend_get_friends($user->uid);
foreach ($users_friends as $id => $value) {
$users_friends_ids[] = $id;
}
return $users_friends;
}
$test = myfunc();
print $test[0];
?>
什么是'故意的'错误? :(
更新代码:
<?php
function myfunc() {
$users_friends = flag_friend_get_friends($user->uid);
foreach ($users_friends as $id => $value) {
$users_friends_ids[] = $id;
}
return $users_friends;
}
$test = myfunc($user);
print $test[0];
?>
恐怕这似乎不起作用。这变成了一场噩梦... – james6848 2011-04-18 15:17:54
你能发布更新后的代码吗? – 2011-04-18 15:58:01
我会在上面贴出来,欢呼声。 – james6848 2011-04-18 16:15:21