Adding an additional condition to a foreach loop

I have some code that I’d like to modify to meet an extra condition but I don’t know how to tackle it.

The code will subitute the keys from “user_cards” with the values of the matching keys found in the “$d” array if the “num_owned” is greater than 0.

So with the data below, the output will be: Maximus Battleframe-6

Can the script be changed so that it will only give an out if:

“num_owned” is greater than 0 && the [2] index from the matching $d array = 2000?

This is the code:
[php]$inventory = array();

foreach ($json[‘user_cards’] as $row => $v){

if ($v[‘num_owned’] > 0){

$inventory[] = $d[$row][0] . “-” . $d[$row][1];

}[/php]

json data sample:

"user_cards": { "43553": { "num_owned": "1", "num_used": "0" }

$d array sample:

$d[43553] = array("Maximus Battleframe",6,2000,6,1);

I solved my problem by using the resources from “http://php.net/manual/en/book.simplexml.php” and adjusting my approach. Thanks

Sponsor our Newsletter | Privacy Policy | Terms of Service