here is my function:
function checkArray($color,$file) {
$color = trim($color);
$settings = getSettings($file,1);
if (in_array($color,$settings)) return true;
else return false;
}
$settings in this context is an array:
Array
(
[0] => Black
[1] => Blackpol
[2] => Blk
[3] => Blue
[4] => Bronz
[5] => Bronze
[6] => Brz
)
i have this function looping a few times with the $color parameter changing each time. sample values are "Black","Blue", etc. long story short, checkArray() should return false very few times.
however, it is returning false EVERY time and i cannot for the life of me figure out why. i tried case insensitive searches, trim, printing individual outputs and comparing the strings ("Black" vs "Black")...i am not new to php or arrays but i can't figure out why this would possibly return false. help please!
PRINT_R of $settings (right before the if statement)
Array
(
[0] => Black
[1] => Blackpol
[2] => Blk
[3] => Blue
[4] => Bronz
[5] => Bronze
[6] => Brz
[7] => Bz
[8] => Cherry
[9] => Gold
[10] => Gun
[11] => Gunmet
[12] => Gunmetal
[13] => Pol
[14] => Poly
[15] => Quentin
[16] => Rootbeer
[17] => Vis
)
VAR DUMP OF $color (right before if statement)
string(5) "Black"
var_dump
of$settings
and$color
right before theif
statement to double check variable values. You may have overlooked something. – Tim Cooper Apr 24 '11 at 17:34$settings
. Can you dump it and show us? – PeeHaa Apr 24 '11 at 17:34return in_array($color, $settings);
– Rafe Kettler Apr 24 '11 at 17:36Array ( [0] => Black [1] => Blackpol [2] => Blk [3] => Blue [4] => Bronz [5] => Bronze [6] => Brz [7] => Bz [8] => Cherry [9] => Gold [10] => Gun [11] => Gunmet [12] => Gunmetal [13] => Pol [14] => Poly [15] => Quentin [16] => Rootbeer [17] => Vis )
vardump $color outputsstring(5) "Black"
– Alex Apr 24 '11 at 17:36var_dump
of$settings
instead of aprint_r
. Looks like you don't havestring
s in$settings
, but another datatype. – Jürgen Thelen Apr 24 '11 at 17:44