I am trying to see if an array contains a string, but am having a ton of problems - no matter what I do it always returns false.
Basically I want to see if a stop on the train matches a particular string. I am trying to see if at any point NAME = Ridgewood.
Below is my code that I am using since it is a multi-dimensional array. Array is below code. I've tried ===
in_array
and even strcmp
and still get FALSE every time.
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);
}
Here is the array I am searching:
[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"
}
}
}
}
STOPS
and the like actually a constant defined in your code? Or are you using the auto-constant-to-string "feature" of PHP? If so, you probably shouldn't; instead use"STOPS"
, etc. – Waleed Khan Jul 18 '13 at 16:29var_export
instead ofvar_dump
? – mattdonders Jul 18 '13 at 16:37