PHP Functions
- What will be the output of the following PHP code ?
<?php
function Condition($number)
{
if ($number == 3)
echo "Condition 3rd executed....";
if ($number == 7)
echo "Condition 7th executed....";
if ($number == 8)
echo "Condition 8th executed....";
if ($number == 19)
echo "Condition 19th executed....";
}
$var = stripos("I know the php, And I love to know php!","the");
Condition($var);
?>
-
View Hint View Answer Discuss in Forum
NA
Correct Option: B
The stripos() function finds the position of the first occurrence of a string inside another string. In this case it returns 7.
- What will be the output of the following PHP code ?
<?php
function fun($m)
{
if ($m < 10)
echo "True";
if ($m >= 10)
echo "False";
}
fun(20);
?>
-
View Hint View Answer Discuss in Forum
NA
Correct Option: D
Argument is 20.
- What will be the output of the following PHP code ?
<?php
$p = 45;
$q = 26;
function add()
{
$GLOBALS['r'] = $GLOBALS['p'] + $GLOBALS['q'];
}
add();
echo $r;
?>
-
View Hint View Answer Discuss in Forum
NA
Correct Option: D
r is a variable present within the $GLOBALS array, it is also accessible from outside the function!
- What will be the output of the following PHP code ?
<?php
function 15function()
{
echo "Hello Interview Mania";
}
15function();
?>
-
View Hint View Answer Discuss in Forum
NA
Correct Option: A
Function cannot begin with a number.
- What will be the output of the following PHP code ?
<?php
function _message()
{
echo "Welcome to the Interview Mania";
}
_message();
?>
-
View Hint View Answer Discuss in Forum
NA
Correct Option: A
Function Beginning with “_” is valid)