Workspace

PHP

web backends CMS and server rendered pages

Definition first

What PHP means

PHP is a programming language for writing exact instructions, often used for web backends CMS and server rendered pages. Start with one mental model: input goes through steps and becomes output.

Minimum run factsFile index.phpRun php index.phpHabit Keep input validation close to request handling
Program

An ordered set of instructions. It reads input, follows rules, and produces output.

Value and variable

A value is data. A variable is the name you use to hold and reuse that data.

Function

A named piece of work. It takes input, does one job, and can return a result.

Runtime

PHP CLI or web server is the place that actually runs code from index.php.

First readable code

Variables

dollar variables echo arrays
<?php
$name = "Ada";
echo $name;
Output Ada

Language lineage

PHP family tree

See where PHP comes from, which languages feel close, and what to learn next.

roots
CPerlCGI
currentPHPServer web scripting family
familyServer web scripting family
best used for

server rendered websites, CMS work, forms, and practical web backends

Zero base path

1Read one rule2Predict output3Type from memory4Run checklist5Repeat with one change

Question bank

Search before practice

Pick a stage or search across the open programming bank. Jump straight to the matching drill.

18 matching questions
Q 1ChoiceStage 1 definitions

PHP practice 1

PHP question 1. Choose the statement that matches variable.

Q 2ChoiceStage 1 definitions

PHP practice 2

PHP question 2. Choose the statement that matches echo.

Q 3ChoiceStage 1 definitions

PHP practice 3

PHP question 3. Choose the statement that matches function.

Q 4ChoiceStage 1 definitions

PHP practice 4

PHP question 4. Choose the statement that matches foreach.

Q 5ChoiceStage 1 definitions

PHP practice 5

PHP question 5. Choose the statement that matches variable.

Q 6ChoiceStage 1 definitions

PHP practice 6

PHP question 6. Choose the statement that matches echo.

Q 7ChoiceStage 1 definitions

PHP practice 7

PHP question 7. Choose the statement that matches function.

Q 8ChoiceStage 1 definitions

PHP practice 8

PHP question 8. Choose the statement that matches foreach.

Q 9ChoiceStage 1 definitions

PHP practice 9

PHP question 9. Choose the statement that matches variable.

Q 10ChoiceStage 1 definitions

PHP practice 10

PHP question 10. Choose the statement that matches echo.

Q 11ChoiceStage 1 definitions

PHP practice 11

PHP question 11. Choose the statement that matches function.

Q 12ChoiceStage 1 definitions

PHP practice 12

PHP question 12. Choose the statement that matches foreach.

Q 13ChoiceStage 1 definitions

PHP practice 13

PHP question 13. Choose the statement that matches variable.

Q 14ChoiceStage 1 definitions

PHP practice 14

PHP question 14. Choose the statement that matches echo.

Q 15ChoiceStage 1 definitions

PHP practice 15

PHP question 15. Choose the statement that matches function.

Q 16ChoiceStage 1 definitions

PHP practice 16

PHP question 16. Choose the statement that matches foreach.

Q 17ChoiceStage 1 definitions

PHP practice 17

PHP question 17. Choose the statement that matches variable.

Q 18ChoiceStage 1 definitions

PHP practice 18

PHP question 18. Choose the statement that matches echo.

Multiple choice

PHP practice 1

Q 1Choicenew

PHP question 1. Choose the statement that matches variable.

$name = "Ada";

Reference

Patterns for index.php

PHP CLI or web serverphp index.php
Recall from memoryRead a small point then write it back without looking
Trace the codeWrite variable values line by line before you run the answer
Type it yourselfCopy less type more and fix one small error at a time

dollar variables echo arrays

Variables

<?php
$name = "Ada";
echo $name;
  • Variables start with dollar sign
  • echo outputs text
  • End statements with semicolons

function parameters return

Functions

function add($a, $b) {
  return $a + $b;
}
  • Use function for reusable work
  • Validate input
  • Return values

indexed associative foreach

Arrays

$user = ["name" => "Ada"];
echo $user["name"];
  • Associative arrays use keys
  • foreach loops through arrays
  • Escape output in HTML