Page 1 of 1
Anther array question
Posted: Sat Jan 24, 2004 8:11 pm
by pinehead18
Bah, another array question

.
$pics = array($row['pic1'],$row['pic2']);
Basically without a foreach loop. I need to say if $pics (which is an array)
if any of the vars in $pics == something other than defualt.gif then post this html.
Any ideas?
Thank you
Anthony
Posted: Sat Jan 24, 2004 8:54 pm
by microthick
There's a function called in_array() that you can use.
$letters = array("a", "b", "c");
if (in_array("c", $letters)) {
// c is in $letters
}
Posted: Sat Jan 24, 2004 9:04 pm
by pinehead18
I tried that. The only problem is if one of the vars in array == image21532.jpg and i am telling in_array("image", $array) then it wont find it.
Suggetsions?
Posted: Sat Jan 24, 2004 9:51 pm
by microthick
So you only want, say, default.gif to be in the array.
Take your array and make a duplicate array to mess around with.
$secondarray = $firstarray;
Then, remove all duplicate entries in the $secondarray.
$secondarray = array_unique($secondarray);
Now, if the array only contains default.gif and nothing else, the array will only contain 1 element and that will be default.gif.
if (count($secondarray) != 1 || !in_array("default.gif", $secondarray)) {
// There are bad values in here.
}
Posted: Sat Jan 24, 2004 10:01 pm
by pinehead18
Kinda, WHat i'm going for is saying
If one of the 4 values in the array is not default.gif then echo the html.
But if all the 4 values are default.gif then don't echo the html.
Thats what i'm attempting to accomplish