-1

I have this Array ($item):

Array
        (

            [categoria] => Array
                (
                    [0] => Array
                        (
                            [tid] => 6737
                            [name] => Sala VIP
                            [endereco] => 
                            [logo] => 
                            [image] => 
                            [link] => /taxonomy/term/6737
                            [site] => 
                            [color] => 
                            [peso] => 0
                            [icone] => 1
                            [url_emissores] => 
                        )

                )

            [destaque] => 1
        )

And i want to compare if $something is equal to [name] => Sala VIP. How can i do this? Im trying:

if($something == $item[categoria][0].name) {
   #code
}
Premlatha
  • 1,676
  • 2
  • 20
  • 40
Vitor Mascia
  • 109
  • 2
  • 9

1 Answers1

0

Like mentioned above, you can access an index of an array like ['someIndex']. But if this array is not a constant, you should ensure that that field is actually set or you will get an undefined index error.

Adding an isset() before comparing will prevent such errors:

if(isset($item['categoria'][0]['name']) && $item['categoria'][0]['name'] === $something) {
   #code
}

Hope this helps,

Miroslav Glamuzina
  • 4,472
  • 2
  • 19
  • 33