Re: [PHP] difference between indexed and associative arrays?
- Date: Wed, 5 Apr 2017 10:51:32 +0200
- From: Narcis Garcia <informatica@xxxxxxxxx>
- Subject: Re: [PHP] difference between indexed and associative arrays?
El 05/04/17 a les 10:31, Jigar Dhulla ha escrit:
> On Wed, Apr 5, 2017 at 1:37 PM, Narcis Garcia <informatica@xxxxxxxxx> 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"
> }
>
>
Then the logic is inverse:
"an indexed array is exactly same as associative array but with only
numeric keys"
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php