IM收到错误
Notice: Array to string conversion php
通过从外部类调用我的数组..任何人都可以在这里发现问题
脚本home.php
echo b::addarray(123, sea, 1);//i tried this way,dint work either("123","sea","1")
die();
带有数组的脚本
class b
{
static function addarray($a,$b,$c){
$red = array();
array_push($red, $a,$b,$c);
return $red;
}
}
答案 0 :(得分:4)
按照以下方式尝试,因为您需要回复array
print_r()
或var_dump()
$re = new b();
$result = $re::addarray(123,'sea',1);
print_r($result);
答案 1 :(得分:3)
sea是一个字符串,应该引用它。试试这个
<?php
class b
{
static function addarray($a,$b,$c){
static $red = array();
array_push($red, $a,$b,$c);
return $red;
}
}
print_r(b::addarray(123, "sea", 1));
?>
答案 2 :(得分:0)
print_r(b::addarray(123, sea, 1));
or
foreach(b::addarray(123, sea, 1) as $key=>$val) {
echo $key."#".$val;
}