[英]Using in_array correctly with array inside array
I want to use in_array to check multiple integers, eg checking integer "427971780" key: amenityId if exist anywhere in the array of a array. 我想使用in_array检查多个整数,例如检查整数“ 427971780”键:amenityId如果存在于数组数组中的任何位置。
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. 我正在使用此php尝试查看数组以查找整数,但它似乎不起作用。
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. 这就是IF语句的原因。
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? 谁能发现上面的for / if代码有问题吗?
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 . 并尝试使用此方法in_array()和多维数组 。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.