Re: perl developer struggling with some php concepts
| From: | Lars Torben Wilson | Date: | Wed, 20 Dec 2000 07:35:40 +0000 |
| Subject: | Re: perl developer struggling with some php concepts | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-31096@lists.php.net to get a copy of this message | ||
Vincent Stoessel writes:
> Hello,
> I'm forwarding this question to the group from a perl developer
> trying to grasp array concepts in php vs perl.
>
> His statement follows:
>
>
>
> Something anamolous in php: finding the highest index of an array is
> non-trivial. There should be some method available that tells what
> the highest index of an array is. In the first example it should be
> two, in the second example it should be 12.
>
> If anyone finds an answer to this, please share it with the group.
> This should be pretty basic.
It is:
<?php
error_reporting(E_ALL);
$arr[1] = 'one';
$arr[10] = 'two';
$largest_ind = max(array_keys($arr));
echo "Max ind is $largest_ind<br>\n";
?>
However, as you've probably already noticed, all arrays in PHP are
associative; it's just that you can use integer keys as well as
strings. So in the above example, array elements between 1 and 10 are
still not set.
Hope this helps,
Torben
--
+----------------------------------------------------------------+
|Torben Wilson <torben@php.net> Netmill iTech|
|http://www.coastnet.com/~torben http://www.netmill.fi|
|Ph: 1 250 383-9735 torben@netmill.fi|
+----------------------------------------------------------------+