如果数组不包含,则删除它的一部分

时间:2015-01-16 18:04:30

标签: php arrays remove-if

我在PHP中有一个名为$ json的数组。看起来像这样

Array ( 
[0] => Array ( 
    [name] => Knife 
    [url] => http://steamcommunity.com/market/listings/753/297120... 
    [price] => 0.16 USD 
    [image] => http://steamcommunity-a.akamaihd.net/economy/imag...
    [quantity] => 30 
    [game] => Counter-Strike: Global Offensive ) 

[1] => Array ( 
    [name] => Strange Knife 
    [url] => http://steamcommunity.com/market/listings/440/Strange%2...
    [price] => 0.55 USD 
    [image] => http://steamcommunity-a.akamaihd.net/economy/imag... 
    [quantity] => 177 
    [game] => Team Fortress 2 ) 

[2] => Array ( 
    [name] => Festive Knife 
    [url] => http://steamcommunity.com/market/listings/440/Festive%20Knife" id="resultlink_2 
    [price] => 3.72 USD 
    [image] => http://steamcommunity-a.akamaihd.net/economy/image/fWFc82js0fmoRAP-qOIPu5THSWqffx
    [quantity] => 66 
    [game] => Team Fortress 2 ) 

[3] => Array ( 
    [name] => â… Flip Knife 
    [url] => http://steamcommunity.com/market/listings/7
    [price] => 3.72 USD 
    [image] => http://steamcommunity-a.akamaihd.net/economy/image/fWFc82js0fmoRAP-qOIPu5THSWqffx
    [quantity] => 24 
    [game] => Counter-Strike: Global Offensive ) 

...

如何删除GAME!=“反恐精英:全球攻势”的阵列的一部分?

1 个答案:

答案 0 :(得分:1)

$array; // Your array.

foreach($array as $subarray) {
    if($subarray['game'] != "Counter-Strike: Global Offensive") {
        unset($subarray);
    }
}