linkedin-skill-assessments-quizzes

PHP

Q1. What does this code output?

echo 76 <=> '76 trombones';

Q2. Which is the most secure way to avoid storing a password in clear text in database?
Q3. What does this script do?
1 $email = filter_input(INPUT_POST, 'email', FILTER_VALIDATE_EMAIL);
2 if ($email === false) {
3  $emailErr = "Please re-enter valid email";
4 }
Q4. In the following script, which line(s) will cause an error(s)?
1 <?php
2       $count = 0
3       $_xval = 5
4       $_yval = 1.0
5       $some_string = "Hello there!";
6       $some_string = "How are you?";
7       $will i work = 6;
8       $3blindmice = 3;
9 ?>
Q5. In a conditional statement, you want to execute the code only if both value are true. Which comparison operator should you use?
Q6. All variables in PHP start with which symbol?
Q7. What is a key difference between GET and POST?
Q8. The _ operator is useful for sorting operations. It compares two values and returns an integer less than, equal to, or greater than 0 depending on whether on whether the value on the _is less than, equal to, or greater than the other.
Q9. Which are valid PHP error handling keywords?
Q10. Which value equates to true?
Q11. What is missing from this code, which is supposed to create a test cookies?
1 $string_name = " testcookie";
2 $string_value = "This is a test cookie";
3 $expiry_info = info()+259200;
4 $string_domain = "localhost.localdomain";
Q12. What is the value of $total in this calculation?

$total = 2 + 5 * 20 - 6 / 3

Q13. What is the purpose of adding a lowercase “u” as a modifier after the final delimiter in a Perl-compatible regular expression?
Q14. Which code snippet uses the correct syntax for creating an instance of the Pet class?
Q15. What is the best way to explain what this script does?
1 if (!\$\_SESSION['myusername'])
2 {
3 header('locaton: /login.php');
4 exit;
5 }
Q16. Which is the correct format for adding a comment to a PHP script?
Q17. PHP supports multiple types of loops. If you wanted to loop through a block of code if and as long a specified condition is true, which type of loop would you use?
Q18. The ignore_user_abort( ) function sets whether a client disconnect should abort a script execution. In what scenario would you, as a web developer, use this function?
Q19. The PHP function array_reduce() takes a callback function that accepts a value carried over each iteration and the current item in the array, and reduces an array to a single value. Which code sample will sum and output the values in the provided array?
1 <?php
2 echo array_reduce([1, 2, 5, 10, 11], function ($item, $carry) {
3 $carry = $carry + \$item;
4 });
5?>
1 <?php
2 echo array_reduce([1, 2, 5, 10, 11], function ($carry, $item) {
3 return $carry = $item + \$item;
4 });
5?>
1 <?php
2 array_reduce([11 2, 5, 10, 11], function ($item, $carry) {
3 echo $carry + $item;
4 });
5?>
1 <?php --CORRECT
2 echo array_reduce([1, 2, 5, 10, 11], function ($carry, $item) {
3 return $carry += $item;
4 });
5?>
Q20. Which PHP script uses a constructor to display the string “Winter is almost over!”?
1 class MyClass { //Maybe
2 public function \_construct()
3 {
4 echo 'Winter is almost over!'."\n";
5 }
6 }
7 \$userclass = new MyClass;
1 class MyClass {
2 public function _construct()
3 {
4 echo 'Winter is almost over!.."\n";
5 }
6 }
7 $userclass = new MyClass;
1 class MyClass {
2 public function \_construct()
3 {
4 echo 'Winter is almost over!.."\n";
5 }
6 }
7 \$userclass = new MyClass;
1 class MyClass {
2 public function _construct()
3 {
4 echo 'Winter is almost over!'."n";
5 }
6 }
7 $userclass = MyClass;
Q21. How might you troubleshoot a “call to undefined function” error?
Q22. Which line could you NOT use to comment out “Space: the final frontier”?
Q23. What displays in a browser when the following code is written? <?php echo “How much are the bananas?”?>
Q24. Which operator would you use to find the remainder after division?
Q25. What is the significance of the three dots in this function signature?
function process(...$vals) {
        // do some processing
 }
Q26. Assuming the Horse class exists, which is a valid example of inheritance in PHP?
Q27. Both triple === and double == can be used to **_ variables in php. If you want to hear that string “33” and the number 33 are equal, you would use ** . If you want to check if an array contains a particular string value at a particular index, you would use ___
Q28. Your php page is unexpectedly rendering as totally blank. Which step will shed light on the problem?
Q29. Which is the way to create an array of “seasons”?
Q30. Both self and this are keywords that can be used to refer to member variables of an enclosing class. The difference is that $this->member should be used for __ members and self::$member should be used for __ members.
Q31. What will this code print?
$mathe=array('archi','euler','pythagoras');
array_push($mathe,'hypatia');
array_push($mathe,'fibonacci');
array_pop($mathe);
echo array_pop($mathe);
echo sizeof($mathe);
Q32. You are using the following code to find a users band, but it is returning false. Which step(s) would solve the problem?

isset (\$\_GET['fav_band'])

Q33. Which code would you use to print all the elements in an array called $cupcakes?
Q34. What is the cause of ‘Cannot modify header information - headers already sent’?
Q35. Which php control structure is used inside a loop to skip the rest of the current loops code and go back to the start of the loop for the next iteration
Q36. The php not operator is !. Given the snippet, is there an out put and what is it?
Q37. You want to list the modules available in your PHP installation. What command should you run?
Q38. For the HTML form below, what is the correct functioning script that checks the input “mail” to be sure it is filled before proceeding?
if (!empty(\$\_POST["mail"])) {
echo "Yes, mail is set";
} else {
echo "No, mail is not set";
} (correct)
Q39. What is the value of ‘$result’ in this calculation?

$result = 25 % 6;

Q40. What is the job of the controller as a component in MVC?
Q41. Why does this code trigger an error?

$string = 'Shylock in a Shakespeare's "Merchangt of Venice" demands his pound of flesh.';

Q43. Assuming that $first_name and $family_name are valid strings, which statement is invalid?
Q44. Which code snippet demonstrates encapsulation?
class Cow extends Animal {
    private $milk;
}
class Cow {
    public $milk;
}
$daisy = new Cow();
$daisy->milk = "creamy";
class Cow {
    public $milk;
    function getMilk() {`
        return $this->milk;
    }
}
class Cow {
    private $milk;
        public function getMilk() {
            return $this->milk;
        }
}
Q45. The following XML document is in books.xml. Which code will output “Historical”?
<books>
    <book>
        <title>A Tale of Two Cities</title>
            <author>Charles Dickens</author>
            <categories>
            <category>Classics</category>
            <category>Historical</category>
            </categories>
            </book>
        <title>Then There Were None</title>
            <author>Agatha Christies</author>
            <categories>
            <category>Mystery</category>
        </categories>
    </book>
</books>
Q46. When it comes to the value of a variable, what is the difference between NULL and empty?
Q47. What would be a good name for this function?
function doStuff($haystack, $needle) {
      $length = strlen($needle)
      if (substr($haystack, 0, $needle) == $needle)
        return true;
      else
        return false;
}
Q48. If you want to pass a formfield to another page when a button is clicked, you should use the _ . If you want to store information across multiple pages, you should use the _?
Q49. You are using the following code to decide if a button is clicked, but it is never returning true. Which step is most likely to shed light on the problem?
isset($_POST['submit'])
Q50. Why should you follow a PSR standard?
Q51. What are getters and setters?