Re: Check for Associative Array
| From: | Richard Lynch | Date: | Fri, 19 Jul 2002 02:07:14 +0000 |
| Subject: | Re: Check for Associative Array | ||
| Groups: | php.general | ||
| Request: | Send a blank email to php-general+get-108407@lists.php.net to get a copy of this message | ||
>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).
All arrays are associative, really. Just some happen to have integers as
their keys in the association.
>I'm using mysql_fetch_array() and I want to foreach only the assoc. part of
>the array without using mysql_fetch_assoc():
So use that extra argument to mysql_fetch_array and tell it you only want
the MYSQL_ASSOC ones, not MYSQL_BOTH.
http://php.net/mysql_fetch_array
>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
It's wrong, but if you want to do it that way, you could use:
http://php.net/next
maybe.
--
Like Music? http://l-i-e.com/artists.htm