-1

I have an array in php called $json. It looks like this

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 ) 

...

How I can remove a part of an array where GAME != "Counter-Strike: Global Offensive" ?

4
  • 3
    Have you tried anything or do you just want us to do your homework?!
    – Rizier123
    Jan 16, 2015 at 18:05
  • 2
    $json = array_filter($json, function($value) { return $value['game'] === 'Counter-Strike: Global Offensive'; });
    – Mark Baker
    Jan 16, 2015 at 18:06
  • Use "strpos" PHP function for each element of the array: php.net/manual/ro/function.strpos.php
    – valicu2000
    Jan 16, 2015 at 18:07
  • Thanks for replay .Its not my homework, am doing it for myself . I searched a lot on stackoverflow and google but cant find and answer.
    – Toni Mhb
    Jan 16, 2015 at 18:08

1 Answer 1

1
$array; // Your array.

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.