Learn to create web applications in PHP with minimal previous experience. This book is a practical guide to using PHP for web development.Loaded with examples and step-by-step instructions, each chapter is dedicated to a specific area or function. You'll first review the main principles of PHP and what is needed to program and develop in it. You'll then study variables, data types, control statements, arrays, and functions, all critical for creating efficient PHP programs. The book then moves on to object-oriented programming (OOP) and how to implement those principles in PHP, as well as inheritance, interfaces, testing, error handling, and exceptions. By the end of PHP by Example, you will have the knowledge and confidence to implement PHP for your web projects both large and small.What You'll LearnUnderstand PHP from the ground upCreate scripts and implement them in real-world projectsWork with a broad toolkit of ready-made exercises and solutionsInvestigate the main constructions of the PHP. Table of Contents About the Author About the Technical Reviewer Acknowledgments Introduction Chapter 1: The First Program The Program’s Code The Interpreter Regime The Server Regime Summary Chapter 2: Variables and Data Types Introduction to Variables Basic Data Types The Arithmetic Operations The Comparison Operations The Logical Operations The Bitwise Operations The Operations with Strings Assigning Values The Ternary Operator Summary Chapter 3: The Control Statements The if Conditional Statement The while Loop Statement The do-while Loop Statement The for Loop Statement The switch Selection Statement The goto Instruction The match Selection Statement Summary Chapter 4: Arrays Getting Familiar with Arrays A Loop over an Array Multidimensional Arrays Array Assignments Concatenating Arrays Comparing Arrays Functions for Handling Arrays Summary Chapter 5: Functions Creating Functions The Function Result The Type of Arguments and Result The Argument Passing Mechanism The Argument Value by Default An Arbitrary Number of Arguments Recursion The eval() Function Anonymous Functions Named Arguments Summary Chapter 6: Useful Tricks and Operations References Constants Global Variables Static Variables Multiline Strings Using Files Including a File in the Program Summary Chapter 7: Classes and Objects The OOP Principles Creating Classes and Objects The Methods The Constructor and the Destructor Static Fields and Methods Copying Objects Private Fields and Methods Special Methods Defining Fields in the Constructor Summary Chapter 8: Inheritance Creating a Child Class Overriding Methods Constructors and Inheritance Inheritance and Private Members Protected Members of a Class Virtual Methods A Function as a Field Value Multilevel Inheritance Summary Chapter 9: Advanced OOP Mechanisms Abstract Classes Interfaces Interface Inheritance Class Inheritance and Interface Implementation Traits Object Type Control A Namespace Anonymous Classes Summary Chapter 10: Error Handling Exception Handling Principles Exception Classes Throwing Exceptions The Custom Exceptions Handling Exceptions of Different Classes Nested try-catch Constructions and the finally Block Rethrowing an Exception The Functions for Handling Errors Summary Chapter 11: Generators and Iterators Getting Familiar with Generators A Generator Function with Arguments An Array Based on a Generator The Generator Result Using Generators Passing a Value to a Generator Iterators Summary Chapter 12: Using PHP A Script in an HTML Document Handling the Request Parameters Using Buttons Using Several Buttons Using Lists and Checkboxes A Slider and Radio Buttons Summary Chapter 13: Afterword: What Was and What Will Be Index