$cars = [ "Maruti" => "200000", "Suzuki" => "400000", ]; var_dump($cars);
Result
array(2) { ["Maruti"]=> string(6) "200000" ["Suzuki"]=> string(6) "400000" }$abc = array ( 1 => "a", "1" => "b", 1.5 => "c", true => "d", ); var_dump($abc);
Results
array(1) { [1]=> string(1) "d" }$array = array( "foo" => "bar", "bar" => "foo", 100 => -100, -100 => 100, ); var_dump($array);
Results
array(4) { ["foo"]=> string(3) "bar" ["bar"]=> string(3) "foo" [100]=> int(-100) [-100]=> int(100) }$fruits = array ('Banana', 'Mango', 'Melon', 'Orange'); var_dump($fruits);
Result
array(4) { [0]=> string(6) "Banana" [1]=> string(5) "Mango" [2]=> string(5) "Melon" [3]=> string(6) "Orange" }It is possible to specify the key only for some elements and leave it out for others:
$abc = array( "a", "b", 6 => "c", "d", 9 => "e", "f", ); var_dump($abc);
Result
array(6) { [0]=> string(1) "a" [1]=> string(1) "b" [6]=> string(1) "c" [7]=> string(1) "d" [9]=> string(1) "e" [10]=> string(1) "f" }$array = array ( "foo" => "bar", 42 => 24, "Multi" => array ( "dimensional" => array ( "array" => "foo" ) ) );array(3) { ["foo"]=> string(3) "bar" [42]=> int(24) ["Multi"]=> array(1) { ["dimensional"]=> array(1) { ["array"]=> string(3) "foo" } } } string(3) "bar" int(24) string(3) "foo"
function getArray(){ return array(1, 2, 3); } var_dump(getArray());
Result
array(3) { [0]=> int(1) [1]=> int(2) [2]=> int(3) } array(2) { [5]=> int(1) [6]=> int(2) } array(3) { [5]=> int(1) [6]=> int(2) [7]=> int(56) } array(4) { [5]=> int(1) [6]=> int(2) [7]=> int(56) ["x"]=> int(42) } array(5) { [5]=> int(1) [6]=> int(2) [7]=> int(56) ["x"]=> int(42) [8]=> int(142) } array(4) { [6]=> int(2) [7]=> int(56) ["x"]=> int(42) [8]=> int(142) }