0% found this document useful (0 votes)
50 views6 pages

What Is The Output of The Following Code?

The document contains 5 multiple choice questions about PHP code snippets. It asks about the output of code that uses arrays, loops, string formatting functions, and variable argument functions. The correct answers are provided at the end.

Uploaded by

losus007
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
50 views6 pages

What Is The Output of The Following Code?

The document contains 5 multiple choice questions about PHP code snippets. It asks about the output of code that uses arrays, loops, string formatting functions, and variable argument functions. The correct answers are provided at the end.

Uploaded by

losus007
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 6

Generated with: ZCE Chrome Extension

Question 1
What is the output of the following code?
$g = range(5,8);
$h = array("a", "b", "c", "e");
for($i = 0; $i < count($g); $i++) {
   foreach ($h as $j) {
      echo $i.$j;
      break;
   }
}

0a1a2a3a

0a0b0c0e1a1b1c1e2a2b2c2e3a3b3c3e

0a0b0c0e

5a6a7a8a

_______________________________________________________________________________________________________________
1/6
Generated with: ZCE Chrome Extension

Question 2
What is the output of the following PHP script?
$foo = 'bar';
echo '$foo\'' . "$foo\'";

$foo'bar\'

bar'$foo\'

$foo'bar

$foobar

_______________________________________________________________________________________________________________
2/6
Generated with: ZCE Chrome Extension

Question 3
Using nl2br() is a handy way to format plain-text for output in a HTML document. What is the
output of the following PHP script?
$str = nl2br("foo\nbar");

# nl2br doesn't remove the \n
$str = str_replace("\n", "", $str);

echo nl2br($str);

Enter the exact script output

foo bar

null

foobar

foo<br />bar

_______________________________________________________________________________________________________________
3/6
Generated with: ZCE Chrome Extension

Question 4
How do you declare a function to accept a variable (unknown) number of arguments in PHP 7?

function foo(@multi $parms) {}

function foo(<multi> $parms) {}

function foo($parms <multi>) {}

function foo(...$parms) {}

_______________________________________________________________________________________________________________
4/6
Generated with: ZCE Chrome Extension

Question 5
What is the output of the following PHP script?
$values = array(37, 5, "09");
sort($values, SORT_STRING);
foreach ($values as $v) {
echo $v;
}

09375

09537

53709

50937

_______________________________________________________________________________________________________________
5/6
Generated with: ZCE Chrome Extension

Answers
Answer for Question 1
A

Answer for Question 2


A

Answer for Question 3


D

Answer for Question 4


D

Answer for Question 5


A

_______________________________________________________________________________________________________________
6/6

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy