PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
Moderator: General Moderators
pinehead18
Forum Contributor
Posts: 329 Joined: Thu Jul 31, 2003 9:20 pm
Post
by pinehead18 » Sat Jan 24, 2004 8:11 pm
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
microthick
Forum Regular
Posts: 543 Joined: Wed Sep 24, 2003 2:15 pm
Location: Vancouver, BC
Post
by microthick » Sat Jan 24, 2004 8:54 pm
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
}
pinehead18
Forum Contributor
Posts: 329 Joined: Thu Jul 31, 2003 9:20 pm
Post
by pinehead18 » Sat Jan 24, 2004 9:04 pm
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?
microthick
Forum Regular
Posts: 543 Joined: Wed Sep 24, 2003 2:15 pm
Location: Vancouver, BC
Post
by microthick » Sat Jan 24, 2004 9:51 pm
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.
}
pinehead18
Forum Contributor
Posts: 329 Joined: Thu Jul 31, 2003 9:20 pm
Post
by pinehead18 » Sat Jan 24, 2004 10:01 pm
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