PHP variables, types, arrays, functions, superglobals, string functions, include and require, and sessions.
39 cards · basic cards · AI-written, checked twice. Edit anything.
- How do you declare a variable in PHP?
Show answer
Use a dollar sign ($) followed by the variable name, for example $name = 'John';
- What are the naming rules for PHP variables?
Show answer
Must start with a dollar sign and a letter or underscore, followed by alphanumeric characters or underscores. Variable names are case-sensitive.
- What is type juggling in PHP?
Show answer
Automatic conversion of a variable from one type to another when an operation requires it.
- How do you explicitly cast a variable to a different type in PHP?
Show answer
Place the desired type in parentheses before the variable: (int)$var, (string)$var, (bool)$var, (array)$var.
- What is the scope of a variable declared inside a function?
Show answer
Local to that function only, and cannot be accessed outside of it unless declared as global.
- What does the PHP string data type store?
Show answer
Text of any length, enclosed in single or double quotes.
- What is the PHP integer data type?
Show answer
A whole number with no decimal point, can be positive or negative.
- What is the PHP float data type?
Show answer
A number with a decimal point or in exponential form, such as 1.5 or 2e3.
- What is the PHP boolean data type?
Show answer
A data type that holds only true or false, commonly used in conditional statements.
- What is the PHP array data type?
Show answer
A data structure that stores multiple values in a single variable, each accessed by an index or key.
- What does the PHP NULL data type represent?
Show answer
An empty variable, assigned by setting a variable to NULL or when a variable is unset.
- What is an indexed array in PHP?
Show answer
An array where elements are accessed by numeric indices starting from 0.
- What is an associative array in PHP?
Show answer
An array where elements are accessed by string keys that you define instead of numeric indices.
- How do you create a multidimensional array in PHP?
Show answer
Nest arrays inside other arrays, for example: $array = array(array(1, 2), array(3, 4));
- What does the count() function return?
Show answer
The number of elements in an array.