搜尋

首頁  >  問答  >  主體

php - 如何在陣列中搜尋並取出想要的數據

1.例如我有一堆陣列如下:

Array
(
    [0] => Array
        (
            [gid] => 1
            [cid] => pc001
            [class] => 办公用品
            [name] => 笔记本电脑
            [type] => Acer Aspire E1-410G
            [unit] => 台
            [num] => 1
            [price] => 
            [amount] => 
            [invoice] => 
            [bremarks] => 
            [bid] => 
        )

    [1] => Array
        (
            [gid] => 2
            [cid] => pc002
            [class] => 办公用品
            [name] => 笔记本电脑
            [type] => Acer Aspire E5-571G-58WT
            [unit] => 台
            [num] => 2
            [price] => 
            [amount] => 
            [invoice] => 
            [bremarks] => 
            [bid] => 
        )

    [2] => Array
        (
            [gid] => 4
            [cid] => wf123
            [class] => 办公用品
            [name] => 鼠标
            [type] => 罗技M90
            [unit] => 个
            [num] => 3
            [price] => 
            [amount] => 
            [invoice] => 
            [bremarks] => 
            [bid] => 
        )

    [3] => Array
        (
            [gid] => 6
            [cid] => wf012
            [class] => 办公用品
            [name] => 电脑键盘
            [type] => PS接口
            [unit] => 个
            [num] => 4
            [price] => 
            [amount] => 
            [invoice] => 
            [bremarks] => 
            [bid] => 
        )

)

2.搜尋條件如下:gid等於如下數組

Array
(
    [0] => 3
    [1] => 4
    [2] => 5
)

3.我如何把gid=3,4,5的資料取出來呢?
如上資料應該只有一條符合要求,求大神幫忙~

给我你的怀抱给我你的怀抱2735 天前728

全部回覆(3)我來回復

  • PHP中文网

    PHP中文网2017-06-05 11:11:37

    foreach($arr_1 as $val){

    雷雷

    }
    print_r($data);

    回覆
    0
  • PHPz

    PHPz2017-06-05 11:11:37

    雷雷

    回覆
    0
  • 漂亮男人

    漂亮男人2017-06-05 11:11:37

    雷雷

    回覆
    0
  • 取消回覆