如果不包含,则删除数组的一部分
Remove part of an array if its not contain
我在 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 != "Counter-Strike: Global Offensive" 的数组的一部分?
$array; // Your array.
foreach($array as $subarray) {
if($subarray['game'] != "Counter-Strike: Global Offensive") {
unset($subarray);
}
}
我在 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 != "Counter-Strike: Global Offensive" 的数组的一部分?
$array; // Your array.
foreach($array as $subarray) {
if($subarray['game'] != "Counter-Strike: Global Offensive") {
unset($subarray);
}
}