note 11221 rejected from function.array by torben
| From: | torben@php.net | Date: | Sat, 14 Jun 2003 19:33:22 +0000 |
| Subject: | note 11221 rejected from function.array by torben | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-50349@lists.php.net to get a copy of this message | ||
Note Submitter: atrox@screaming-penguin.com
----
actually it is quite easy to directly reference a value in an array relatively.
you simply must reset and sort the array first (see reset and sort)
also note that when using dynamically assigned arrays that potentially may have only one element,
sort does not re-index the array from zero, so in each case where an array could potentially only
have one element you must count the array, if it has one element then re-assign it with an index of
zero (to ensure that it is zero after it is processed) if it has more than one element then sort
will do the work for you: example:
reset($array);
sort($array);
$count = count($array);
if ($count == 1)
{
$value = current($array);
$array = array ("0" => "$value");
}
in this manner the array is reset and sorted FIRST and then counted, if the count is 1, then it is
rebuilt with an index of 0 (note that sort re-indexes beggining with 0 if the array has multiple
elements)