Skip to main content

Functions — Part 1 MCQs with Explanations

Practice high-yield Programming & Software Development MCQs on Functions — Part 1 with worked academic solutions for FPSC, PPSC, NTS, NITB, PTS.

Questions
40
Difficulty Level
Exam-Level
Target Exams
FPSC, PPSC, NTS...
Estimated Time
48 mins
Exam-Level FPSC PPSC NTS NITB PTS
Verified for Commission Syllabus • Oct 14, 2026
40

Verified Practice Questions

Interactive test mode with detailed academic worked solutions

Live Progress | 0/40 answered
✓ 0 correct ✗ 0 wrong 0% score
Question 1 of 40
★ FPSC ★ PPSC

Type Hinting was introduced in which version of PHP?

Question 2 of 40
★ FPSC ★ PPSC

What will happen in this function call? <?php function calc ( $price, $tax ) { $total = $price + $tax; } $pricetag = 15 ; $taxtag = 3 ; calc ( $pricetag, $taxtag ) ; ?>

Question 3 of 40
★ FPSC ★ PPSC

What will be the output of the following PHP code? <?php function calc ( $price, $tax = "" ) { $total = $price + ( $price * $tax ) ; echo "$total" ; } calc ( 42 ) ; ?>

Question 4 of 40
★ FPSC ★ PPSC

Which of the following are valid function names? 1. function() 2. €() 3. .function() 4. $function()

Question 5 of 40
★ FPSC ★ PPSC

What will be the output of the following PHP code? <?php function a () { function b () { echo 'I am b' ; } echo 'I am a' ; } a () ; a () ; ?>

Question 6 of 40
★ FPSC ★ PPSC

What will be the output of the following PHP code? <?php function a () { function b () { echo 'I am b' ; } echo 'I am a' ; } b () ; a () ; ?>

Question 7 of 40
★ FPSC ★ PPSC

What will be the output of the following PHP code? <?php $op2 = "blabla" ; function foo ( $op1 ) { echo $op1; echo $op2; } foo ( "hello" ) ; ?>

Question 8 of 40
★ FPSC ★ PPSC

A function in PHP which starts with ______ (double underscore) is know as.

Question 9 of 40
★ FPSC ★ PPSC

What will be the output of the following PHP code? <?php function foo ( $msg ) { echo "$msg" ; } $var1 = "foo" ; $var1 ( "will this work" ) ; ?>

Question 10 of 40
★ FPSC ★ PPSC

Which one of the following PHP functions can be used to build a function that accepts any number of arguments?

Question 11 of 40
★ FPSC ★ PPSC

Which one of the following PHP functions can be used to find files?

Question 12 of 40
★ FPSC ★ PPSC

Which of the following PHP functions can be used to get the current memory usage?

Question 13 of 40
★ FPSC ★ PPSC

Which of the following PHP functions can be used for generating unique id’s?

Question 14 of 40
★ FPSC ★ PPSC

Which one of the following functions can be used to compress a string?

Question 15 of 40
★ FPSC ★ PPSC

What will be the output of the following PHP code? <?php echo "chr(52)" ; ?>

Question 16 of 40
★ FPSC ★ PPSC

What will be the output of the following PHP code? <?php echo ord ( "hi" ) ; ?>

Question 17 of 40
★ FPSC ★ PPSC

What will be the output of the following PHP code? <?php $str = "Hello World" echo wordwrap( $str, 5 , "n" ) ; ?>

Question 18 of 40
★ FPSC ★ PPSC

What will be the output of the following PHP code? <?php echo ( atan ( 0.50 )); ?>

Question 19 of 40
★ FPSC ★ PPSC

What will be the output of the following PHP code? <?php define ( "GREETING" , "Hello you! How are you today?" ) ; echo constant ( "GREETING" ) ; ?>

Question 20 of 40
★ FPSC ★ PPSC

What will be the output of the following PHP code? <?php define ( "GREETING1" , "Hello you! How are you today?" ) ; define ( "GREETING2" , "Hello you! How are you today?" ) ; define ( "GREETING3" , "Hello you! How are you today?" ) ; echo defined ( "GREETING" ) ; ?>

Question 21 of 40
★ FPSC ★ PPSC

What will be the output of the following PHP code? <?php function sum ( $num1, $num2 ) { $total = $num1 + $num2; echo "chr($total)" ; } $var1 = "sum" ; $var1 ( 5, 44 ) ; ?>

Question 22 of 40
★ FPSC ★ PPSC

What will be the output of the following PHP code? <?php function sum ( $num1, $num2 ) { $total = $num1 + $num2; echo "cos($total)"; } sum ( 5 ,- 5 ) ; ?>

Question 23 of 40
★ FPSC ★ PPSC

What will be the output of the following PHP code? <?php function b() { echo "b is executed" ; } function a() { b () ; echo "a is executed" ; b () ; } a () ; ?>

Question 24 of 40
★ FPSC ★ PPSC

What will be the output of the following PHP code? <?php function addFunction ( $num1, $num2 ) { $sum = $num1 + $num2; return $sum; } $return_value = addFunction ( 10 , 20 ) ; echo "Returned value from the function : $return_value" ?>

Question 25 of 40
★ FPSC ★ PPSC

What will be the output of the following PHP code? <?php function sayHello () { echo "HelloWorld<br />" ; } $function_holder = "sayHello" ; $function_holder () ; ?>

Question 26 of 40
★ FPSC ★ PPSC

What will be the output of the following PHP code? span> function one () { echo " this works" ; function two () { echo "this too works" ; } } one () ; two () ; ?>

Question 27 of 40
★ FPSC ★ PPSC

What will be the output of the following PHP code? <?php function do( $myString ) { echo strpos ( $myString , "donkey",0 ); } do ( "The donkey looks like a horse." ); ?>

Question 28 of 40
★ FPSC ★ PPSC

What will be the output of the following PHP code? <?php function one span> () { define ( "const","I am awesome!" ); echo constant ( "const" ); } one () ; ?>

Question 29 of 40
★ FPSC ★ PPSC

What will be the output of the following PHP code? <?php echo hex2bin( "48656c6c6f20576f726c6421" ); ?>

Question 30 of 40
★ FPSC ★ PPSC

What will be the output of the following PHP code? <?php $str = addslashes ( 'What does "yolo" mean?' ); echo ($str); ?>

Question 31 of 40
★ FPSC ★ PPSC

What will be the output of the following PHP code? <?php $str = "Hello world. It's a beautiful day." ; print_r (explode( " ",$str )) ; ?>

Question 32 of 40
★ FPSC ★ PPSC

What will be the output of the following PHP code? <?php echo strtr ( "Hilla Warld","ia","eo" ); ?>

Question 33 of 40
★ FPSC ★ PPSC

What will be the output of the following PHP code? <?php echo stripos( "I love php, I love php too!","PHP" ); ?>

Question 34 of 40
★ FPSC ★ PPSC

What will be the output of the following PHP code ? <?php function A1 ( $x ) { switch ( $x ) { case 1 : //this statement is the same as if($x == 1) echo 'Case 1 was executed.' ; break ; case 2 : //this statement is the same as if($x == 2) echo 'Case 2 was executed.' ; break ; case 3 : //this statement is the same as if($x == 3) echo 'Case 3 was executed.' ; break; case 4 : //this statement is the same as if($x == 4) echo 'Case 4 was executed.' ; break ; default : //this statement is the same as if $x does not equal the other conditions echo 'Default was executed.' ; break ; } } A1 ( 9 ) ; ?>

Question 35 of 40
★ FPSC ★ PPSC

What will be the output of the following PHP code ? <?php function TV ( $string ) { echo "my favourite TV show is " .$string; function b() { echo " I am here to spoil this code" ; } } b () ; ?>

Question 36 of 40
★ FPSC ★ PPSC

What will be the output of the following PHP code ? <?php function TV ( $string ) { echo "my favourite TV show is " .$string; function b () { echo " I am here to spoil this code" ; } } function b () { echo " I am here to spoil this code" ; } b () ; ?>

Question 37 of 40
★ FPSC ★ PPSC

What will be the output of the following PHP code ? <?php function TV ( $string ) { echo "my favourite TV show is " .$string; function b () { echo " I am here to spoil this code" ; } } function b () { echo " I am here to spoil this code" ; } b () ; TV ( "Sherlock" ) ; ?>

Question 38 of 40
★ FPSC ★ PPSC

What will be the output of the following PHP code ? <?php function TV ( $string ) { echo "my favourite TV show is " . $string; function b () { echo " I am here to spoil this code" ; } } a ( "Sherlock" ) ; b () ; ?>

Question 39 of 40
★ FPSC ★ PPSC

What will be the output of the following PHP code ? <?php function calc ( $num1, $num2 ) { $total = $num1 * $num2; } $result = calc( 42, 0 ); echo $result; ?>

Question 40 of 40
★ FPSC ★ PPSC

What will be the output of the following PHP code ? <?php function calc ( $num1, $num2 ) { $total = $num1 * $num2; return $total; } $result = calc ( 42, 0 ) ; echo $result; ?>

✓ Link copied to clipboard
Continue Your Practice

Advance Html — Part 1

Master the next curriculum module with 40 exam-standard MCQs.

Next Practice Set →

💡 Examiner's Advisory for Programming & Software Development

In competitive commission exams (FPSC, PPSC, KPPSC, SPSC, CSS, PMS), questions are frequently phrased with distractor options designed to catch rote learners. Whenever you answer an MCQ, read the Detailed Academic Explanation and Conceptual Anchor to understand why the remaining options are incorrect.

More Modules in Programming & Software Development

View All →
📚

Study Guides

Topic summaries and syllabus breakdown

Explore Guides →
🎯

Complete Library

Search through 78,000+ verified MCQs

Browse Library →
📱

Mobile App

Offline mock tests and instant bookmarks

Get Mobile App →