dongyaofu0599 2018-08-23 13:45
浏览 31
已采纳

在php中按值搜索和取消数组中的数组

My array look like this :

[cart_seller] => Array
    (
        [3] => Array
            (
                [หมวด1เลือก1 หมวด2เลือก1 1705] => Array
                    (
                    )

            )

        [4] => Array
            (
                [@ 801] => Array
                    (
                    )

            )

    )

[cart_product] => Array
    (
        [หมวด1เลือก1 หมวด2เลือก1 1705] => Array
            (
                [id] => 1705
                [name] => ทดสอบสินค้า
                [image] => p1534937865-VASAVAT LAB N MEDIA LOGO W.png
                [price] => 1111
                [option] => หมวด1เลือก1 หมวด2เลือก1 
                [amount] => 1
            )

        [@ 801] => Array
            (
                [id] => 801
                [name] => โบว์แพรแถบ ร.9 ชนมพรรษา 84 พรรษา ปีพุทธศักราช 2554
                [image] => p1498062217-ส.jpg
                [price] => 90
                [option] => 
                [amount] => 1
            )

    )

I want unset '@ 801' in cart_seller and cart_product

in cart_product use unset($cart['cart_product'][@ 801]);

but in cart_seller it in array [4] what can i do without reference value (4) ?

exapmle unset($cart['cart_seller'][xxxx][@ 801]);

  • 写回答

1条回答 默认 最新

  • doumi4676 2018-08-23 13:59
    关注

    Just loop cart seller array til you find @801.

    foreach($cart['cart_seller'] as $key => $c){
        if(array_key_exists("@801",$c)){
            unset($cart['cart_seller'][$key]['@801']);
        }
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 关于大棚监测的pcb板设计
  • ¥15 stm32开发clion时遇到的编译问题
  • ¥15 lna设计 源简并电感型共源放大器
  • ¥15 如何用Labview在myRIO上做LCD显示?(语言-开发语言)
  • ¥15 Vue3地图和异步函数使用
  • ¥15 C++ yoloV5改写遇到的问题
  • ¥20 win11修改中文用户名路径
  • ¥15 win2012磁盘空间不足,c盘正常,d盘无法写入
  • ¥15 用土力学知识进行土坡稳定性分析与挡土墙设计
  • ¥70 PlayWright在Java上连接CDP关联本地Chrome启动失败,貌似是Windows端口转发问题