Re: [PHP] difference between indexed and associative arrays?

[email protected] (Jigar Dhulla)
Newsgroups php.general
Message-ID <CAO=0E+xvQuFYiQ6Cw2QYhkDWoEAvt_3F4ye3TkHWWtUUmnP5mQ@mail.gmail.com>
On Wed, Apr 5, 2017 at 1:37 PM, Narcis Garcia <[email protected]> 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
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.