php associative array key value code example
Example 1: Associative array in php
<?php
/*
There are 3 Types of array in php
1. Indexed arrays - Arrays with a numeric index
2. Associative arrays - Arrays with named keys
3. Multidimensional arrays - Arrays containing one or more arrays
This is the second one - Associative arrays
*/
$age = array("Samy"=>"35", "Naveen"=>"37", "Amit"=>"43");
echo "Mr.Samy is " . $age['Samy'] . " years old.";
?>
Example 2: array key value php
<?php
$age=array("Peter"=>"35","Ben"=>"37","Joe"=>"43");
foreach($age as $x=>$x_value)
{
echo "Key=" . $x . ", Value=" . $x_value;
echo "<br>";
}
?>
Example 3: associative array php
// Associative Array in PHP
/******** ARRAY TYPES ************************************************
There are basically 03 Types of array in php
1. Indexed arrays => Arrays with a numeric index
2. Associative arrays => Arrays with named keys
3. Multidimensional arrays => Arrays containing one or more arrays
***********************************************************************/
//EXAMPLE
//This is the second one - Associative arrays
$age = array("Peter"=>"35", "Naveen"=>"37", "Amit"=>"43");
echo "Mr.Samy is " . $age['Peter'] . " years old.";