What will be the output value of the following code?
$array = array(1,2,3);
while (list(,$v) = each($array));
var_dump(current($array));
What is the output of the following code?
for ($i = 0; $i < 1.02; $i += 0.17) {
$a[$i] = $i;
}
echo count($a);
What is the output of the following code?
function increment ($val)
{
$_GET['m'] = (int) $_GET['m'] + 1;
}
$_GET['m'] = 1;
echo $_GET['m'];
Given the following code, what will the output be:
trait MyTrait {
private $abc = 1;
public function increment() {
$this->abc++;
}
public function getValue() {
return $this->abc;
}
}
class MyClass {
use MyTrait;
public function incrementBy2() {
$this->increment();
$this->abc++;
}
}
$c = new MyClass;
$c->incrementBy2();
var_dump($c->getValue());
How many times will the function counter() be executed in the following code?
function counter($start, &$stop)
{
if ($stop > $start)
{
return;
}
counter($start--, ++$stop);
}
$start = 5;
$stop = 2;
counter($start, $stop);
How should class MyObject be defined for the following code to work properly? Assume $array is an array and MyObject is a user-defined class.
$obj = new MyObject();
array_walk($array, $obj);
Consider the following two files. When you run test.php, what would the output look like?
test.php:
include "MyString.php";
print ",";
print strlen("Hello world!");
MyString.php:
namespace MyFramework\String;
function strlen($str)
{
return \strlen($str)*2; // return double the string length
}
print strlen("Hello world!")
Consider the following table data and PHP code. What is a possible outcome?
Table data (table name "users" with primary key "id"):
id name email
------- ----------- -------------------
1 anna alpha@example.com
2 betty beta@example.org
3 clara gamma@example.net
5 sue sigma@example.info
PHP code (assume the PDO connection is correctly established):
$dsn = 'mysql:host=localhost;dbname=exam';
$user = 'username';
$pass = '********';
$pdo = new PDO($dsn, $user, $pass);
$cmd = "SELECT name, email FROM users LIMIT 1";
$stmt = $pdo->prepare($cmd);
$stmt->execute();
$result = $stmt->fetchAll(PDO::FETCH_BOTH);
$row = $result[0];
What will be the result of the following operation?
array_combine(array("A","B","C"), array(1,2,3));
You want to access the 3rd character of a string, contained in the variable $test. Which of the following possibilites work? (Choose 2)
Which PHP function is used to validate whether the contents of $_FILES['name']['tmp_name'] have really been uploaded via HTTP?
What is the output of the following code?
$a = 'a'; $b = 'b';
echo isset($c) ? $a.$b.$c : ($c = 'c').'d';
Given a php.ini setting of
default_charset = utf-8
what will the following code print in the browser?
header('Content-Type: text/html; charset=iso-8859-1');
echo '✂✔✝';
What is the return value of the following code?
strpos("me myself and I", "m", 2)
Under what condition may HTTP headers be set from PHP if there is content echoed prior to the header function being used?
Which sentence describes the following regular expression match?
preg_match('/^\d+(?:\.[0-9]+)?$/', $test);
When uploading a file to a PHP script using the HTTP PUT method, where would the file data be found?
What is the output of the following code?
echo 0x33, ' monkeys sit on ', 011, ' trees.';
What function can reverse the order of values in an array so that keys are preserved?
What is the output of the following code?
class a
{
public $val;
}
function renderVal (a $a)
{
if ($a) {
echo $a->val;
}
}
renderVal (null);
Which value will be assigned to the key 0 in this example?
$foo = array(true, '0' => false, false => true);