我试图查看一个数组是否包含一个字符串,但是遇到了很多问题——无论我做什么,它总是返回 false。
基本上我想看看火车上的停靠点是否与特定的字符串匹配。我正在尝试查看是否在任何时候 NAME = Ridgewood。
下面是我正在使用的代码,因为它是一个多维数组。数组在代码下方。我已经尝试过===
in_array
,甚至strcmp
每次都得到 FALSE。
foreach ($stationResults as $item) {
$stationStops = $item[STOPS][STOP];
foreach ($stationStops as $stopitem) {
$stationName = $stopitem[NAME];
echo $stationName;
echo "<br />";
if ($stationName === "Ridgewood") {
$stationExists = TRUE;
}
else $stationExists = FALSE;
}
var_dump($stationExists);
}
这是我正在搜索的数组:
[0]=>
array(18) {
["ITEM_INDEX"]=>
string(1) "0"
["SCHED_DEP_DATE"]=>
string(19) "12:35:00 07/18/2013"
["DESTINATION"]=>
string(14) "Ridgewood -SEC"
["TRACK"]=>
string(1) "8"
["LINE"]=>
string(4) "BERG"
["TRAIN_ID"]=>
string(4) "1257"
["STATUS"]=>
string(8) "Boarding"
["BACKCOLOR"]=>
string(6) "Silver"
["FORECOLOR"]=>
string(5) "black"
["SHADOWCOLOR"]=>
string(6) "silver"
["GPSLATITUDE"]=>
string(0) ""
["GPSLONGITUDE"]=>
string(0) ""
["GPSTIME"]=>
string(21) "7/18/2013 12:20:34 PM"
["TRAIN_LINE"]=>
string(18) "Bergen County Line"
["STATION_POSITION"]=>
string(1) "0"
["LINEABBREVIATION"]=>
string(4) "BERG"
["INLINEMSG"]=>
string(0) ""
["STOPS"]=>
array(1) {
["STOP"]=>
array(8) {
[0]=>
array(2) {
["NAME"]=>
string(18) "Secaucus Lower Lvl"
["TIME"]=>
string(21) "7/18/2013 12:45:30 PM"
}
[1]=>
array(2) {
["NAME"]=>
string(10) "Rutherford"
["TIME"]=>
string(21) "7/18/2013 12:53:15 PM"
}
[2]=>
array(2) {
["NAME"]=>
string(8) "Garfield"
["TIME"]=>
string(21) "7/18/2013 12:58:30 PM"
}
[3]=>
array(2) {
["NAME"]=>
string(12) "Plauderville"
["TIME"]=>
string(20) "7/18/2013 1:01:15 PM"
}
[4]=>
array(2) {
["NAME"]=>
string(18) "Broadway Fair Lawn"
["TIME"]=>
string(20) "7/18/2013 1:06:00 PM"
}
[5]=>
array(2) {
["NAME"]=>
string(17) "Radburn Fair Lawn"
["TIME"]=>
string(20) "7/18/2013 1:09:15 PM"
}
[6]=>
array(2) {
["NAME"]=>
string(19) "Glen Rock Boro Hall"
["TIME"]=>
string(20) "7/18/2013 1:12:30 PM"
}
[7]=>
array(2) {
["NAME"]=>
string(9) "Ridgewood"
["TIME"]=>
string(20) "7/18/2013 1:16:00 PM"
}
}
}
}