Re: Check for Associative Array
| From: | Martin Clifford | Date: | Thu, 18 Jul 2002 17:19:10 +0000 |
| Subject: | Re: Check for Associative Array | ||
| Groups: | php.general | ||
| Request: | Send a blank email to php-general+get-108303@lists.php.net to get a copy of this message | ||
Try this:
while($row = mysql_fetch_assoc($result)) {
// code here
}
This way, the resulting array will ONLY be associative.
HTH!
Martin Clifford
Homepage: http://www.completesource.net
Developer's Forums: http://www.completesource.net/forums/
>>> Henning Sittler <Henning@inscriber.com> 07/18/02 12:57PM >>>
What's the best way to check for an Associative Array? There is no
is_assoc() or similiar function listed in the manual (I don't think anyway).
I'm using mysql_fetch_array() and I want to foreach only the assoc. part of
the array without using mysql_fetch_assoc():
foreach ($arr as $key=>$value) {
echo "$key:$value";
}
But of course it show both the indexed array and the assoc array contents.
Is there an existing function to check this, or should I do one of these
things inside the foreach loop:
A) set $last=value and just check if $value = $lastval
B) check if the $key is just a number or just a string
C) $key += 1
?? Thanks,
Henning Sittler
www.inscriber.com
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php