At 08:52 20.03.2003, cpaul said:
--------------------[snip]--------------------
>ok thanks - that makes sense. sort of doesn't solve my problem, because
>if my function receives an enumerated array, i want it to treat it as an
>associative array, using the value as the key.
--------------------[snip]--------------------
What would be the value then?
If I get you correctly, you would treat an array that comes like
[0] => entry 0
[1] => entry 1
[2] => entry 2
as
[entry 0] => ??
[entry 1] => ??
[entry 2] => ??
What happens when there are duplicate values in the source array? You will
loose entries on duplicate values.
If I got you right here have a look at array_flip()
(http://www.php.net/manual/en/function.array-flip.php) to exchange array sides.
You can't tell with absolute certainty if an array is enumerated, or built
as associative array. Take this example:
$a = array('one','two','three');
$b = array(); $b[0] = 'one'; $b[1] = 'two'; $b[2] = 'three';
$c = array(0 => 'one', 1 => 'two', 2 => 'three');
Which one would you believe is enumerated, and which one is associative?
What you can do is walk the array keys and check if there is at least a
single non-numeric key. If you found one the array is associative. If you
found none it may be likely that the array is enumerated, but you can't be
sure in a general way, except your application is designed in a way that
uses always non-numeric keys for associative arrays.
--
>O Ernest E. Vogelsinger
(\) ICQ #13394035
^ http://www.vogelsinger.at/
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php