🎓 A1Learner
🔍
0 of 38 lessons completed

PHP Intermediate Introduction

PHP Intermediate is a course that deepens the class, array and function skills from the beginner course. Each lesson adds one new idea and proves it with small programs.

A class with a method prints a line

The Greeter class holds one method. An object made from the class runs the method and prints the line.

<?php
class Greeter {
  public function greet() {
    echo "Hello from a class\n";
  }
}
$greeter = new Greeter();
$greeter->greet();

asort sorts an array by value

asort puts the scores from low to high. Each name stays with its score, and print_r shows the new order.

<?php
$scores = ["Bo" => 70, "Ana" => 90, "Cy" => 60];
asort($scores);
print_r($scores);

Example

<?php
class Book {
  public $title = "";
  public function show() {
    echo "Book: " . $this->title . "\n";
  }
}
$prices = ["Dune" => 12, "Emma" => 9];
foreach ($prices as $title => $price) {
  $book = new Book();
  $book->title = $title;
  $book->show();
  echo "Price: " . $price . "\n";
}

Key points

  • This course goes deeper into classes and objects.
  • Later lessons split code across files and load classes on their own.
  • Array lessons sort and reshape arrays with small helper functions.
  • String lessons search text and match text patterns.
  • Exception lessons catch errors and keep a program running.
  • File lessons write and read files on the server.
  • Form lessons read sent data and check it before use.
  • The last lessons work with dates and JSON text, and with a database through PDO.

In this example, the prices array pairs each book title with a price. The foreach loop takes one pair at a time. A Book object takes the title, and the show method prints it before the price line.

Try it Yourself

Edit the code, then press Run.

Running is simulated

Exercise

What does this course do with the skills from the beginner course?