associative array in php code example
Example 1: how to create an associative array in php
"BMW",
"carTwo" => "VW",
"carThree" => "Mercedes"
];
echo $associativeArray["carTwo"] . " Is a german brand";
?>
Example 2: Associative array in php
"35", "Naveen"=>"37", "Amit"=>"43");
echo "Mr.Samy is " . $age['Samy'] . " years old.";
?>
Example 3: how to create associative array in php
'valueOne',
'keyTwo'=>'valueTwo'
);
$d = [
'keyOne'=>'valueOne',
'keyTwo'=>'valueTwo'
];
/*
3 - Multidimensional array
*/
$c = array(
'keyOne'=>array('a','b','c'),
'keyTwo'=>array('a'=>'1','b'=>'2')
);
$d = [
'keyOne'=>['a','b','c'],
'keyTwo'=>['a'=>'1','b'=>'2']
];
?>
Example 4: array associativo php
"35", "Naveen"=>"37", "Amit"=>"43");
echo "Mr.Samy is " . $age['Peter'] . " years old.";
?>
Example 5: php define variables from array associative
'foo',
'key2' => 'bar',
];
extract($array);
echo $key1; //print foo
echo $key2; //print bar
?>
Example 6: associative array in php
$age = array("Peter""35", "Ben""37", "Joe""43");