0

I want to use in_array to check multiple integers, e.g checking integer "427971780" key: amenityId if exist anywhere in the array of a array.

The structure of the array is:

array(43) {
[0]=>
 array(2) {
 ["amenityId"]=>
 int(427971780)
 ["amenity"]=>
 string(28) "24-timers fitnessfaciliteter"
}
[1]=>
 array(2) {
 ["amenityId"]=>
 int(359778141)
 ["amenity"]=>
 string(27) "Antal bygninger/højhuse -3"
}

I'm using this php trying to look into the arrays an finding the integer but it doesen't seem to work.

If I do a

var_dump($hotelAmenities[0]['amenityId']); 

it works fine. But I need it to be dynamic, looking up multiple integers. That's the reason for the IF sentence.

 for($x=0;$x<50;$x++){
if(in_array("427971780", $hotelAmenities[$x]['amenityId'])){
 echo "<li><i class='im im-bar'></i><span class='booking-item-feature-title'>Bar/Lounge</span></li>";
 }
 }

Can anyone spot for is wrong with the for/if code above?

Troels Johannesen
  • 725
  • 2
  • 7
  • 30
  • 1
    possible duplicate of [in\_array() and multidimensional array](http://stackoverflow.com/questions/4128323/in-array-and-multidimensional-array) – Rizier123 Feb 28 '15 at 15:24

1 Answers1

0

Your code is wrong. Try this.

for ($x = 0; $x < 50; $x ++) {
    if (in_array('427971780', $hotelAmenities[$x])) {
        echo "<li><i class='im im-bar'></i><span class='booking-item-feature-title'>Bar/Lounge</span></li>";
    }
}

And try to use this method in_array() and multidimensional array.

Community
  • 1
  • 1
Wilon
  • 117
  • 1
  • 6