这是我试图分解字符串的代码,但出现了一些错误,我得到了绳子,但我没有爆炸,我犯了一些错误,我无法理解遇到PHP错误
严重性:警告消息:explode((要求参数2为字符串,对象给定的文件名:views/testing.php行号:65
这是我的代码:
<?php
foreach ($test as $t)
{
echo $t->user_rights;
$t=(explode(",", $t));
}
?>
希望这将帮助您:
foreach ($test as $t)
{
/* this will trigger an error since $t->user_rights is an array .
To use explode $t->user_rights should be a string
*/
$user_rights = (explode(",", $t->user_rights));
print_r($user_rights);
}
更新:
如果您想要user_rights
的逗号分隔值,则必须使用implode()
而不是explode()
;
foreach ($test as $t)
{
$user_rights = implode(",", $t->user_rights);
echo $user_rights ;
}
更多信息:http://php.net/manual/en/function.implode.php
也许您可以使用内爆($t(转换$t。例如:$t=爆炸(",",内爆($t((;
<?php
foreach ($test as $t){
$t=(explode(",",$t->user_rights));
}
?>