我无法在函数内获取数组,但可以在函数外获取。当我在函数外部获取它并将其回显时,它打印出 1,但在函数内部,使用相同的获取数组代码并将其回显,它回显为 null。我知道是因为 --- 符号回显了,但数字 1 没有。我很困惑,因为如果它在函数外工作,同样的代码应该在函数内工作,对吧?除非我做错了什么?请帮忙。谢谢。
<?php
include('connect.php');
include('username.php');
//include('functionGet.php');
$boo = $_GET['boo'];
echo "$boo";
function getData($select,$from,$where,$equals){
$fetch = mysql_fetch_array(mysql_query("SELECT acceptedChallenges FROM
userLogin WHERE username = '$username'"));
$fetch = $fetch['acceptedChallenges'];
echo "---$fetch---";
}
if($boo = 'yes'){
$acceptedChallenges =
getData("acceptedChallenges","userLogin","username",$username);
$fetch = mysql_fetch_array(mysql_query("SELECT acceptedChallenges FROM
userLogin WHERE username = '$username'"));
$fetch = $fetch['acceptedChallenges'];
echo "$acceptedChallenges$username$fetch";
//mysql_query("UPDATE userLogin SET openChallenges = '0' WHERE username =
'$username'");
//mysql_query("UPDATE userLogin SET acceptedChallenges =
'$acceptedChallenges' WHERE username = '$username'");
}
else{
}
?>
最佳答案
你传递的是 $where
而不是 $username
所以改变
function getData($select,$from,$where,$equals){
到
function getData($select,$from,$username,$equals){
关于php - 无法在函数 PHP 中获取数组,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30247361/