PHP Basics and Syntax Flashcards
(25 cards)
What is PHP?
PHP is a server-side scripting language used for web development.
PHP (Hypertext Preprocessor) runs on a server to generate dynamic web content, like WordPress pages. Freelancers use PHP to build custom WordPress plugins or themes, while enterprise architects leverage it for scalable web applications, ensuring robust backend logic.
What are PHP tags?
PHP tags (<?php ?>) enclose PHP code in a file.
These tags tell the server to process the enclosed code as PHP. In WordPress, PHP tags are used in theme files like index.php. Freelancers ensure proper tag usage, while enterprise architects maintain clean code structure for large systems.
What is a PHP variable?
A variable stores data, prefixed with $, like $name = “John”;.
Variables hold values (e.g., strings, numbers) for dynamic use. In WordPress, variables like $post store post data. Freelancers use variables for client features, while enterprise architects manage them for efficient data handling.
What is a string in PHP?
A string is a sequence of characters, like “Hello, World!”.
Strings are used for text output, such as post titles in WordPress. Freelancers manipulate strings in templates, while enterprise architects ensure proper encoding (e.g., UTF-8) for global systems.
What is an integer in PHP?
An integer is a whole number, like 42 or -10.
Integers are used for counts, like post IDs in WordPress. Freelancers use them in loops or calculations, while enterprise architects ensure type safety in large-scale applications.
What is a float in PHP?
A float is a number with a decimal point, like 3.14.
Floats are used for prices in WooCommerce or calculations. Freelancers handle floats for client e-commerce, while enterprise architects validate them for precision in financial systems.
What is a boolean in PHP?
A boolean is a value of true or false.
Booleans control logic, like checking if a WordPress user is logged in (is_user_logged_in()). Freelancers use them in conditionals, while enterprise architects apply them in decision-making processes.
What is the echo statement in PHP?
Answer: echo outputs data to the browser, like echo “Hello”;.
In WordPress, echo displays content in templates. Freelancers use it for dynamic output, while enterprise architects prefer secure output functions to prevent vulnerabilities.
What is the print statement in PHP?
print outputs data, similar to echo, like print “Hello”;.
Less common than echo, print is used in WordPress for simple output. Freelancers may use it in themes, while enterprise architects favor echo or templating for consistency.
What is a PHP comment?
A comment is non-executable code, like // single-line or /* multi-line */.
Comments document code, useful in WordPress plugins for clarity. Freelancers add comments for client handovers, while enterprise architects use them for maintainable, collaborative projects.
What is the assignment operator in PHP?
The assignment operator (=) assigns a value to a variable, like $x = 5;.
Used in WordPress to set variables (e.g., $title = get_the_title();). Freelancers rely on it for dynamic data, while enterprise architects ensure proper variable initialization.
What is the addition operator in PHP?
The addition operator (+) adds numbers, like $sum = 2 + 3;.
Used in WordPress for calculations, like totaling cart items. Freelancers apply it in e-commerce, while enterprise architects validate inputs for accurate computations.
What is the concatenation operator in PHP?
The concatenation operator (.) joins strings, like $greeting = “Hello” . “ World”;.
In WordPress, it combines text for output (e.g., post titles). Freelancers use it in templates, while enterprise architects ensure proper string handling for security.
What is the equality operator in PHP?
The equality operator (==) checks if values are equal, like if ($x == 5).
Used in WordPress for conditions (e.g., checking post types). Freelancers use it in logic, while enterprise architects prefer strict comparison (===) for type safety.
What is the strict equality operator in PHP?
The strict equality operator (===) checks value and type, like if ($x === 5).
Ensures exact matches, useful in WordPress for secure comparisons. Freelancers use it for reliability, while enterprise architects enforce it for robust code.
What is an if statement in PHP?
An if statement executes code if a condition is true, like if ($x > 0) { echo “Positive”; }.
Used in WordPress for conditional logic (e.g., if (is_single())). Freelancers apply it for dynamic features, while enterprise architects optimize conditionals for performance.
What is an else statement in PHP?
An else statement runs code if an if condition is false, like else { echo “Negative”; }.
In WordPress, it handles alternative cases (e.g., displaying fallback content). Freelancers use it for flexibility, while enterprise architects ensure clear logic flows.
What is an elseif statement in PHP?
An elseif checks additional conditions, like elseif ($x == 0) { echo “Zero”; }.
Used in WordPress for multi-case logic (e.g., checking user roles). Freelancers implement it for complex conditions, while enterprise architects streamline it for readability.
What is a constant in PHP?
A constant is an unchangeable value defined with define(), like define(“SITE_NAME”, “MySite”);.
In WordPress, constants like WP_DEBUG configure settings. Freelancers use them for fixed values, while enterprise architects define constants for system-wide configurations.
What is the var_dump() function?
var_dump() displays detailed information about a variable, like var_dump($array);.
Useful for debugging WordPress code (e.g., inspecting $post). Freelancers use it for troubleshooting, while enterprise architects pair it with advanced debugging tools.
What is type casting in PHP?
Type casting converts a variable’s type, like $num = (int)”123”;.
In WordPress, casting ensures correct data types (e.g., post IDs as integers). Freelancers use it for data validation, while enterprise architects enforce it for type safety.
What is the include statement in PHP?
include loads an external PHP file, like include “header.php”;.
In WordPress, it’s similar to get_template_part(). Freelancers use it for reusable code, while enterprise architects prefer require for critical dependencies.
What is the require statement in PHP?
require loads an external PHP file and halts on failure, like require “config.php”;.
Unlike include, require ensures essential files are loaded. Freelancers use it in plugins, while enterprise architects rely on it for system integrity.
What is the difference between include and require?
include continues execution on failure; require stops with an error.
In WordPress, require is used for critical files like wp-config.php. Freelancers choose based on need, while enterprise architects use require for robust systems.