PHP Functions
- What will be the output of the following PHP code ?
<?php
$num = 120;
function calc()
{
echo $num;
}
calc();
?>
-
View Hint View Answer Discuss in Forum
NA
Correct Option: A
$num is not global and hence is not available for calc().
- What will be the output of the following PHP code ?
<?php
function str($Message)
{
$Message = ucwords($Message);
echo lcfirst($Message);
}
str("this is important...");
?>
-
View Hint View Answer Discuss in Forum
NA
Correct Option: A
ucwords() changes all the first letters to capitals. lcfirst() changes first letter of a string to small.
-
<?php
function car()
{
$car = array("Jeep", "Datsun", "Lada", "spyker");
foreach ($car as $val)
{
echo "$val\n";
}
}
car();
?>
-
View Hint View Answer Discuss in Forum
NA
Correct Option: A
For each function causes the program to loop through each array value once.
- What will be the output of the following PHP code ?
<?php
function SumFun($number1, $number2)
{
$s = $number1 + $number2;
return $s;
}
$return_val = SumFun(15, 45);
echo "Returned value : " .$return_val
?>
-
View Hint View Answer Discuss in Forum
NA
Correct Option: A
Returned value : 60
- What will be the output of the following PHP code ?
<?php
function fun($str)
{
echo strtr("Towe Pa55", "ow5", $str);
}
fun("ims");
?>
-
View Hint View Answer Discuss in Forum
NA
Correct Option: A
The strtr() function translates certain characters in a string.