dongren1986 2018-03-07 14:43
浏览 441
已采纳

如何将字典样式值添加到PHP数组?

I'm using PHP 5.4 and trying to add dictionary-style complex values to an array thusly:

array_push($qbProductsArray, $qbProduct => $authNetAmount);

I get this error:

Parse error: syntax error, unexpected '=>'

My desired result is to have a series of $qbProduct and $authNetAmount that are related together. I don't want to add them separately like this:

array_push($qbProductsArray, $qbProduct, $authNetAmount);

...because those 2 values are related to each other, and I don't want them just all thrown in together, even though they are adjacent. I want a firmer link between them. How can this be done?

  • 写回答

1条回答 默认 最新

  • dongtanhe4607 2018-03-07 14:45
    关注

    try adding them as array:

    array_push($qbProductsArray, array($qbProduct => $authNetAmount));
    

    using the => syntax outside of the context of array is not possible in PHP.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

    报告相同问题?

    悬赏问题

    • ¥15 我需要在PC端 开两个抖店工作台客户端.(语言-java)
    • ¥15 有没有哪位厉害的人可以用C#可视化呀
    • ¥15 可以帮我看看代码哪里错了吗
    • ¥15 设计一个成绩管理系统
    • ¥15 PCL注册的选点等函数如何取消注册
    • ¥15 问一下各位,为什么我用蓝牙直接发送模拟输入的数据,接收端显示乱码呢,米思齐软件上usb串口显示正常的字符串呢?
    • ¥15 Python爬虫程序
    • ¥15 crypto 这种的应该怎么找flag?
    • ¥15 代码已写好,求帮我指出错误,有偿!
    • ¥15 matlab+波形匹配算法