PHP questions, answered with working code.
Search explained answers, or work through a guide from your first script to namespaces.
Popular: password_hash · PDO · sessions · array_map · json_decode
Guides
Introduction to PHP
Syntax, variables, arrays, functions, forms and basic security.
14 sections
IntermediateSessions & Cookies
Keep state between requests: creating cookies, storing and destroying session data.
9 sections
AdvancedNamespaces
Organise larger codebases, avoid name collisions and understand name resolution.
7 sections
From the knowledge base
-
How does using separate get() and set() methods in PHP classes affect code readability compared to using a single function with return?
Using separate get() and set() methods in PHP classes can improve code readability by clearly separating the logic for getting and setting properties of an obje...
PHP classes get() -
What are best practices for starting PHP sessions in functions or scripts?
When starting PHP sessions in functions or scripts, it is best practice to first check if a session has already been started before starting a new one to preven...
session_start PHP functions -
Are there specific PHP settings that should be avoided when trying to override configurations with a local php.ini file?
When trying to override configurations with a local php.ini file, it's important to avoid settings that are already defined as PHP_INI_SYSTEM, as these cannot b...
PHP settings local php.ini file override configurations