PHP Syntax and Basics Flashcards
Q: What does PHP stand for?
A: PHP: Hypertext Preprocessor.
Q: What is PHP primarily used for?
A: Server-side scripting for web development.
Q: How do you start and end a block of PHP code?
A: <?php to start and ?> to end.
Q: What is the correct way to output text in PHP?
A: Using echo or print.
Q: How do you add a single-line comment in PHP?
A: Use // or #.
Q: How do you declare a variable in PHP?
A: Use the $ symbol, e.g., $variable_name = “value”;.
Q: What are the common data types in PHP?
A: String, Integer, Float, Boolean, Array, Object, NULL.
Q: What function is used to get the data type of a variable?
A: gettype().
Q: How do you check if a variable is set?
A: Use the isset() function.
Q: How do you unset a variable in PHP?
A: Use the unset() function.
Q: How do you define a constant in PHP?
A: Using the define() function.
Q: Can constants be changed after they are set?
A: No, constants are immutable.
Q: What is the correct syntax for defining a constant?
A: define(“CONSTANT_NAME”, “value”);.
Q: How do you access a constant?
A: Use the constant name directly, e.g., CONSTANT_NAME.
Q: What is the difference between define() and const?
A: const is used for class constants and must be defined in the global scope.
Q: What are the arithmetic operators in PHP?
A: +, -, *, /, %.