function update_user_voted($array,$userid=NULL)
{
global $db;
//$voted = array();
if(!$userid)
$userid = userid();
if(phpversion < '5.2.0')
{
global $json;
$js = $json;
}
if(is_array($array))
{
$votedDetails = $db->select(tbl("users"),"voted"," userid = '$userid'");
if(!empty($votedDetails))
if(!empty($js))
$voted = $js->json_decode($votedDetails[0]['voted'],TRUE);
else
$voted = json_decode($votedDetails[0]['voted'],TRUE);
//$votedArray = $voted;
$voted[] = $array;
if(!empty($js))
$votedEncode = $js->json_encode($voted);
else
$votedEncode = json_encode($voted);
if(!empty($votedEncode))
$db->update(tbl("users"),array("voted"),array("|no_mc|$votedEncode")," userid='$userid'");
}
}
当我使用此功能时,它可以正常工作,但仅显示此错误:
警告:无法在第5160行的/ mydirectory / thisfile中包含thiscode.php的标量值作为数组使用(
$voted[] = $array;
)。Apache版本2.2.27
PHP版本5.3.28
MySQL版本5.5.34-cll-lve
架构x86_64
操作系统linux
还说这个错误是新的,我从未遇到过此功能的问题。在片段存储脚本中使用。
最佳答案
在增加索引之前,必须将$ voted声明为数组。您试图将具有复杂结构(也可以是标量值)的新元素推入数组,如果json数据返回标量,则不应使用$ voted []推入。
$ voted = array();