PHP Data Types Quiz

Quiz 2 12 questions

Prerequisites for the quiz

  1. PHP Data Types
  2. All previous chapters

Are you ready?

12 questions to solve

Instructions
  1. This quiz goes to full-screen once you press the Start button.
  2. At the end of the quiz, you are able to review all the questions that you answered wrong and see their explanations.
Which of the following values are of a scalar type?
  1. 5
  2. 'Hello'
  3. true
As stated in the PHP Data Types chapter, there are four scalar types in PHP: integers, floats, strings and Booleans. Hence, the correct choice here is (D).
Which of the following types are scalar types?
  1. Integer
  2. Boolean
  3. Array
As stated in the PHP Data Types chapter, there are four scalar types in PHP: integers, floats, strings and Booleans. Hence, the correct choice here is (A).
Which of the following is a floating-point number?
Of the given options, only (B) is a float. Choice (A) represents an integer while choice (C) represents a string. Hence, the correct choice is (B). Refer to PHP Data Types for more information.
PHP has separate types for integers and floats. True or false?
Yes, PHP has separate types for integers and floats. This goes with choice (A). Refer to PHP Data Types for more information.
What does the following code output?
<?php

$s = 'Hello';
echo $s[1];
$s[1] retrieves the second character of the string $s, i.e. 'e'. Hence, the code outputs e, and this goes with choice (B). Refer to PHP Data Types for more information.
How to get the total number of characters of a string variable $str?
The strlen() function returns the total number of characters, also known as the length, of a given string. Hence, the correct choice is (C). Refer to PHP Data Types for more information.
Which of the following denotes a Boolean in PHP?
In PHP, the naming of keywords is case-insensitive. That is, whether we use true or TRUE, or True, the keyword refers to the same Boolean value true. Hence, the correct choice is (D). Refer to PHP Data Types for more information.
In the code below, what is the value stored in the variable $a called?
<?php

$a = [1, 2];
Refer to PHP Data Types for more information.
What does the following code output?
<?php

$arr = [1, -5, 11, 10];
sort($arr);

print_r($arr);
The print_r() function prints an array in a readable way, just as shown in choice (C). Refer to PHP Data Types for more information.
What does the following code output?
<?php

echo gettype('');
gettype() returns the type of the given value in a readable way. In the case of a string, it returns 'string'. Hence, the correct choice in this case is (B). Refer to PHP Data Types — gettype() for more information.
Which of the following functions is used to check whether a given value is a string or not?
The is_string() function is used to check whether a given value is a string or not. Refer to PHP Data Types — Strings for more information.
Which of the following functions is used to check whether a given value is an integer or not?
The is_int() function is used to check whether a given value is an integer or not. Refer to PHP Data Types — Integers for more information.