Register Now

Login

Lost Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

What will be the output of the following PHP code?
<?php
$age = array(“Harry” => “21”, “Ron” => “19”, “Malfoy” => “23”);
ksort($age);
foreach($age as $x => $x_value)
{
echo “Key=” . $x . “, Value=” . $x_value;
echo “<br>”;
}
?>

What will be the output of the following PHP code?
<?php
$age = array(“Harry” => “21”, “Ron” => “19”, “Malfoy” => “23”);
ksort($age);
foreach($age as $x => $x_value)
{
echo “Key=” . $x . “, Value=” . $x_value;
echo “<br>”;
}
?>
a) Key = Harry, Value = 21
Key = Ron, Value = 21
Key = Malfoy, Value = 23
b) Key = Harry, Value = 21
Key = Ron, Value = 19
Key = Malfoy, Value = 23
c) Key = Harry, Value = 21
Key = Malfoy, Value = 23
Key = Ron, Value = 19
d) Key = Ron, Value = 19
Key = Harry, Value = 21
Key = Malfoy, Value = 23

Answer: c
Explanation: The ksort() function sorts an associative array in ascending order, according to the key

Join The Discussion