Questions
PHP questions
Choose a question page, learn the concept, then test your understanding with a quiz.
HTTP_HOST vs SERVER_NAME in PHP: What’s the Difference?
Learn the difference between $_SERVER['HTTP_HOST'] and $_SERVER['SERVER_NAME'] in PHP, when to use each, and common pitfalls.
How PHP foreach Actually Works with Arrays
Learn how PHP foreach works internally, including array copies, internal pointers, by-value vs by-reference behavior, and common pitfalls.
How to Add Elements to an Empty Array in PHP
Learn how to add values to an empty array in PHP using [] and array_push(), with examples, common mistakes, and real-world usage.
How to Add a New Column to an Existing Table in a Laravel Migration
Learn how to add a new column to an existing table in Laravel using migrations, Schema::table, and artisan commands.
How to Calculate the Difference Between Two Dates in PHP
Learn how to calculate the difference between two dates in PHP using DateTime and DateInterval, with examples and common mistakes.
How to Capture var_dump Output to a String in PHP
Learn how to capture var_dump output as a string in PHP using output buffering, with examples, pitfalls, and practical debugging use cases.
How to Change Maximum Upload File Size in PHP
Learn how PHP upload size limits work, which settings control them, and what to do when you cannot access php.ini or .htaccess.
How to Check If a String Is Valid JSON in PHP
Learn the correct and efficient way to check whether a string contains valid JSON in PHP using json_decode and json_last_error.
How to Check String Prefixes and Suffixes in PHP
Learn how to check whether a string starts or ends with specific text in PHP using simple functions and practical examples.
How to Check Whether a PHP Session Has Started
Learn how to safely detect and start PHP sessions, avoid duplicate session_start() calls, and handle $_SESSION correctly in PHP.
How to Check if a PHP Array Is Associative or Sequential
Learn how to detect associative vs sequential arrays in PHP, with clear examples, edge cases, and practical patterns for real code.
How to Check if a String Contains a Word in PHP
Learn how to check whether a PHP string contains a specific word using strpos and str_contains with clear examples and common mistakes.
How to Check if a String Starts With a Prefix in PHP
Learn how to check whether a string starts with a specific prefix in PHP, with simple examples, common mistakes, and practical use cases.
How to Check if an Array Is Empty in PHP
Learn how to check whether an array is empty in PHP, including empty strings, exploded values, and safe patterns for real codebases.
How to Convert a String to a Number in PHP
Learn how to convert strings like '2' or '2.34' to numbers in PHP using casting, numeric checks, and safe conversion patterns.
How to Copy Arrays in PHP: Assignment, References, and Safe Copies
Learn how PHP array copying works, including assignment, references, and safe ways to copy arrays between variables and objects.
How to Create Custom Helper Functions in Laravel
Learn how to create globally available custom helper functions in Laravel for reusable text formatting and cleaner Blade views.
How to Create a Directory If It Does Not Exist in PHP and WordPress
Learn how to check whether a folder exists and create it safely in PHP and WordPress, including practical examples and common mistakes.
How to Create and Use Empty Objects in PHP
Learn how to create empty PHP objects, initialize nested properties safely, and choose between stdClass, arrays, and typed classes.
How to Delete an Array Element by Value in PHP
Learn how to remove an array element by value in PHP using array_search and unset, with examples, pitfalls, and practical patterns.