1 view
Test — PHP Developer 1. What will be the result of executing this PHP code? ```php $item = 5; $list = [1, 2, 3]; foreach ($list as $item) { $item++; echo $item; ``` 2. What will be the output? ```php $a = null; var_dump(isset($a)); $b = $a; var_dump(isset($b)); ``` 3. What will be the output? ```php $a = ""; var_dump(isset($a)); var_dump(empty($a)); $a = '0'; var_dump(empty($a)); ``` 4. What will be the output? ```php $x = 1; if ($x == '1') { ```
Asked at
AI answer
-
Output:
234— on each iteration,$itemreceives the element's value, then is incremented by one. (The example assumes a closing brace forforeach.) -
Output:
bool(false)
bool(false)
isset() returns false for a variable whose value is null.
- Output:
bool(true)
bool(true)
bool(true)
isset() considers an empty string to be a set variable, while empty() considers both "" and the string '0' to be empty.
- The snippet is truncated, so its output cannot be determined. The condition
$x == '1'is true when$x = 1.
Also asked at AutoSpot
- Tell us about yourself as a developer — experience, stack, projects.
- What are your salary expectations?
- Do you have experience writing and working with native SQL queries or similar low-level commands to a database?
- What AI tools do you use and for what tasks?
- What do you know about indexes? How can you determine which indexes are used in a query, and how can you tell which indexes are unnecessary or missing?
Similar questions
- What will be the output? ```php $x = 1; if ($x == '1') { echo 'a'; } if ($x == true) { echo 'b'; } if ((bool)$x === true) { echo 'e'; } if ($x === true) { echo 'c'; } if ((int)$x === true) { echo 'd'; } ```
- What will be the output: ```php if ((bool)$x === true) { echo 'e'; } if ($x === true) { echo 'c'; } if ((int)$x === true) { echo 'd'; } ``` What will be the output: ```php $preview = 0; if (($preview == 1) || ($preview == 'On')) { $opp = "+"; } else { $opp = "-"; } echo $opp; ``` What will be the output: ```php $arr = ["b", "o", "m"]; if (array_search('b', $arr)) { echo 'Yes'; } else { echo 'No'; } ```
- What will var_dump(isset($a)) output for null and a subsequent assignment?
- 7. What will be the output? ```php class A { public $i = 0; } class C { public function increment($i) { $i++; } public function update($obj) { $obj->i = 10; } } // part 1 $a = new A(); $a->i = 1; $b = $a; $b->i += 1; echo $a->i . ', ' . $b->i; // part 2 $c = new C(); $c->increment($a->i); echo $a->i; // part 3 $c->update($a); echo $a->i; ``` 8. What will be the output? ```php $a = "20"; $a -= 5; ```
- What does empty() return for an empty string and zero?