php - Difference between a non-associated array and an associated array where the keys are string intergers -



php - Difference between a non-associated array and an associated array where the keys are string intergers -

are next 3 arrays identical, or can told apart? if so, how?

$array1=array('abc','def','ghi'); $array2=array('0'=>'abc','1'=>'def','2'=>'ghi'); $array3=array(0=>'abc',1=>'def',2=>'ghi');

a simple test have prevented confusion you.

<?php $array1=array('abc','def','ghi'); $array2=array('0'=>'abc','1'=>'def','2'=>'ghi'); $array3=array(0=>'abc',1=>'def',2=>'ghi'); print_r($array1); print_r($array2); print_r($array3);

output

array ( [0] => abc [1] => def [2] => ghi ) array ( [0] => abc [1] => def [2] => ghi ) array ( [0] => abc [1] => def [2] => ghi )

do see difference? none whatsoever.

are next 3 arrays identical, or can told apart?

yes identical , no cannot told apart.

note illustration php.net

<?php $array = array( 1 => "a", "1" => "b", 1.5 => "c", true => "d", ); var_dump($array); ?>

read this

as keys in above illustration cast 1, value overwritten on every new element , lastly assigned value "d" 1 left over.

that means 0 , "0" mean same thing, end :)

php arrays

Comments

Popular posts from this blog

php - Android app custom user registration and login with cookie using facebook sdk -

c# - Create a Notification Object (Email or Page) At Run Time -- Dependency Injection or Factory -

Set Up Of Common Name Of SSL Certificate To Protect Plesk Panel -