Fatal error: Unsupported operand types in PHP

Fatal error: Unsupported operand types in PHP

我有那个代码,我想将 corp_resp 乘以 corp_resp_template 并动态求和。

$total = (array_reduce((array_map(function($x, $y) { return $x * $y; },
                   $corp_resp, $corp_resp_template)),function($carry,$item){return $carry+=$item;},0));
echo $total;

代码:

 $valor[] = array();
   foreach ( $_POST as $key => $value ){

       $valor[] = $value;

corp_resp 输出:

array(17) { [0]=> array(0) { } [1]=> string(4) "0.00" [2]=> string(4) "0.00" [3]=> string(4) "0.00" [4]=> string(4) "0.00" [5]=> string(4) "0.50" [6]=> string(4) "0.00" [7]=> string(4) "0.00" [8]=> string(4) "0.00" [9]=> string(4) "0.00" [10]=> string(4) "0.50" [11]=> string(4) "0.00" [12]=> string(4) "0.00" [13]=> string(4) "0.00" [14]=> string(4) "0.00" [15]=> string(4) "0.00" [16]=> string(4) "0.00" } 

代码:

$corp_resp_template = array();

while ($mostrar = mysql_fetch_array($consulta)) {

$corp_resp_template[] = $mostrar['corp_resp_template'];
}

corp_resp_template 输出:

array(17) { [0]=> string(4) "0.15" [1]=> string(4) "0.15" [2]=> string(4) "0.15" [3]=> string(4) "0.15" [4]=> string(4) "0.15" [5]=> string(4) "0.15" [6]=> string(4) "0.15" [7]=> string(4) "0.15" [8]=> string(4) "0.15" [9]=> string(4) "0.15" [10]=> string(4) "0.15" [11]=> string(4) "0.15" [12]=> string(4) "0.15" [13]=> string(4) "0.15" [14]=> string(4) "0.15" [15]=> string(4) "0.15" [16]=> string(4) "0.15" } 

出现以下错误:Fatal error: Unsupported operand types in C: 其中 2 是数组。

另一个疑问是当我有 corp_resp_template 并且我想在同一个函数中为不同 corp_resp 计算结果时如何工作?

已通过 array_shift 函数解决。两个变量的格式数组不同,这就是为什么会出现该错误。