At 12:40 18.03.2003, Awlad Hussain said:
--------------------[snip]--------------------
>I have an associative like array["name"]="hello";
>I am trying to get two random values from the array, the key name and the
>value, but using the codes below from the PHP manual i am getting the inex
>key value rather than the name.
>
>$rand_keys = array_rand ($input, 2);
>print $input[$rand_keys[0]]."\n";
>print $input[$rand_keys[1]]."\n";
>
>so instead of getting two random values like key=name & value="hello" i am
>getting key=0 and value=hello.
--------------------[snip]--------------------
array_rand only operates on the "value side" of an array. To retrieve
random keys from an associative array, use array_keys() of the assoc. array
as input rather that the assoc. array itself:
$rand_keys = array_rand (array_keys($input), 2);
print $input[$rand_keys[0]]."\n";
print $input[$rand_keys[1]]."\n";
--
>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