Wap in PHP to show how will your work with associative, indexed arrays.
Answers
Answer:
The associative arrays have names keys that is assigned to them. ... Let us see an example− $arr = array( "p"=>"150", "q"=>"100", "r"=>"120", "s"=>"110", "t"=>"115"); Above, we can see key and value pairs in the array.
Explanation:
There are two ways to create an associative array:
$age = array("Peter"=>"35", "Ben"=>"37", "Joe"=>"43");
or:
$age['Peter'] = "35";
$age['Ben'] = "37";
$age['Joe'] = "43";
The named keys can then be used in a script:
Example
<?php
$age = array("Peter"=>"35", "Ben"=>"37", "Joe"=>"43");
echo "Peter is " . $age['Peter'] . " years old.";
?>
Try it Yourself »
Loop Through an Associative Array
To loop through and print all the values of an associative array, you could use a foreach loop, like this:
Example
<?php
$age = array("Peter"=>"35", "Ben"=>"37", "Joe"=>"43");
foreach($age as $x => $x_value) {
echo "Key=" . $x . ", Value=" . $x_value;
echo "<br>";
}
?>
Try it Yourself »
Complete PHP Array Reference
For a complete reference of all array functions, go to our complete PHP Array Reference.
The reference contains a brief description, and examples of use, for each function!
PHP Exercises
Test Yourself With Exercises
PLZ MARK ME BRAINLIEST
Create an associative array containing the age of Peter, Ben and Joe.
$age = array("Peter""35", "Ben""37", "Joe""43");