获取错误:PHP致命错误:不支持的操作数类型

时间:2018-03-25 15:38:00

标签: php

我只需要这些PHP专家的帮助。我对PHP有一点了解。我收到了此代码的PHP Fatal error: Unsupported operand types

$ticket_item_types += array(
    val_paperworkticket => 19,
    val_disposal => 9,
    comment => 22,
    loadtime => 20,
    bbls => 23,
    disposalticketno => 46,
    load_reviewed => 31
);

2 个答案:

答案 0 :(得分:1)

如果键是变量,则必须在变量名之前使用$,因此它必须是:

$ticket_item_types += array(
    $val_paperworkticket => 19,
    $val_disposal => 9,
    $comment => 22,
    $loadtime => 20,
    $bbls => 23, 
    $disposalticketno => 46,
    $load_reviewed => 31
);

如果它们是字符串,则必须引用它们:

$ticket_item_types += array(
    'val_paperworkticket' => 19,
    'val_disposal' => 9,
    'comment' => 22,
    'loadtime' => 20,
    'bbls' => 23,
    'disposalticketno' => 46,
    'load_reviewed' => 31

);

另外,请考虑带有数组的+运算符不能理解为sum运算符,而是Union运算符

  

+运算符返回附加到左侧数组的右侧数组;对于存在于两个数组中的键,将使用左侧数组中的元素,并且将忽略右侧数组中的匹配元素。

Array Operator (PHP docs)

答案 1 :(得分:0)

您的问题来自您的操作+ =。

如果$ ticket_item_types是一个数组,你应该使用array_push。

否则,

$ ticket_item_types = array(val_paperworkticket => 19,val_disposal => 9,comment => 22,loadtime => 20,bbls => 23,disposalticketno => 46,load_reviewed => 31) ;

应该删除问题。