How does PHP index associative arrays? -
as know, in associative arrays
, if keys not set, set automatically. seem doesn't make sense in case:
$a = array( '1' => 'one', '3', '2' => 'two'); print_r($a);
outputs:
array ( [1] => 1 [2] => 2 )
so '3'?
within user defined array assigning keys manually array means as
array(1 => 'one',3, 2 => 'two');//[1] => 1 [2] => 3 [2] => 2
here have two identical index , per docs mentioned last overwrite first
syntax "index => values", separated commas, define index , values. index may of type string or integer. when index omitted, integer index automatically generated, starting @ 0. if index integer, next generated index biggest integer index + 1.
note when 2 identical index defined, last overwrite first.
in order filter case can make changes as
array(1 => 'one',2 =>'two',3) // array ([1] => 1 [2] => 2 [3] => 3) array(3,1 => 'one',2 =>'two') //array ([0] => 3 [1] => 1 [2] => two) array(1 => 'one',2 => 3 ,3 =>'two')// array([1] => 1 [2] => 3 [3] => two)
Comments
Post a Comment