Re: difference between indexed and associative arrays?
| From: | Jigar Dhulla | Date: | Wed, 05 Apr 2017 08:31:14 +0000 |
| Subject: | Re: difference between indexed and associative arrays? | ||
| References: | 1 2 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-326053@lists.php.net to get a copy of this message | ||
On Wed, Apr 5, 2017 at 1:37 PM, Narcis Garcia <informatica@actiu.net> wrote:
> As I understand, an associative array is exactly same as indexed array
> but with an additional "property": the key.
>
>
> El 04/04/17 a les 23:54, Jeffry Killen ha escrit:
> > Is there a function that will produce the difference between indexed and
> > associative arrays, without actually testing for string or integer
> indices?
> >
> > (Although I realize that arrays can be mixed string and integer indeces..)
> >
> > Thank you for time and attention.
> > JK
> >
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>
Indexed array has key property too, difference is that key are always
indexed (as name suggest).
Also,
$a = [2 => 'foo', 4 => 'bar', 6 => 'baz'];
$a[] = 'foo1';
$a[] = 'bar1';
var_dump($a);
Here keys(2 and 4) stays as is and keys(1 & 3) will be skipped. And next
key will largest key value + 1.
Output:
array(5) {
[2] =>
string(3) "foo"
[4] =>
string(3) "bar"
[6] =>
string(3) "baz"
[7] =>
string(4) "foo1"
[8] =>
string(4) "bar1"
}
--
Regards,
Jigar Dhulla