An array() function used for create an array.
Syntax
Numeric array
array(value1,value2,value3,value4,etc.);
Associative array
array(key1=>value1,key2=>value2,key3=>value3,key4=>value4,etc.);
Example 1 Numeric array
$num=array(1,2,3,4,5);
foreach($num as $value){
echo "value is ".$value."<br/>";
}
Output
value is 1
value is 2
value is 3
value is 4
value is 5
Example 2 Associative array
$age = array("ram"=>"30", "shyam"=>"32", "ravi"=>"34");
foreach($age as $key => $value) {
echo "Key=" . $key . ", Value=" . $value;
echo "<br>";
}
Output
Key=ram, Value=30
Key=shyam, Value=32
Key=ravi, Value=34
Copyright ©2022 coderraj.com. All Rights Reserved.