Composite pattern in PHP
The Composite pattern lets you compose objects into uniform interface hierarchies. The power of this pattern is that both composite and leaf objects share a common method. When you call it on a composite object, it propagates through the entire hierarchy.

Use cases
A book structure with chapters (composite elements) and pages (leaf elements). You have a common method countWords() on both types. If you call it on a chapter, it counts words throughout its hierarchy.

Another use case is a file system with directories and files and a common method display(). If you call it on a directory, it shows its name and the names of its children.

Another example could be a game with spaceships (leaf elements) and coordinator ships (composite elements). Both have a method launchAttack(). If you call it on a coordinator ship, it launches an attack from itself and its children.

An HTML form is also a good example. You have simple elements like buttons or inputs and composite elements like fieldsets. A render() method on a root form node renders the root and its children.

Example: file system structure
We define a FileSystemComponent interface with a display() method. File is the leaf class. Directory is the composite class that can have children.
We create instances of leaf and composite objects, add leaves to composites, and display the whole hierarchy by calling display() on the root composite.
The interface: FileSystemComponent
Leaf class: File
Composite class: Directory
The client code
When you run this code, you get:
Directory: Root
Directory: Folder 1
File: file1.txt
File: file2.txt
File: file3.txt
Video
In the following video you can see the complete process (Spanish audio).