Subscribe to PHP Freaks RSS

TutsPlus.com: PHP Control Structures and Loops: if, else, for, foreach, while and More

syndicated from www.phpdeveloper.org on October 15, 2018

On the TutsPlus.com site today they're "getting back to basics" with a tutorial targeted at those just learning the PHP language. In this latest tutorial, they focus on control structures and loops such as if, else, for, foreach, while and more.

In simple terms, a control structure allows you to control the flow of code execution in your application. Generally, a program is executed sequentially, line by line, and a control structure allows you to alter that flow, usually depending on certain conditions.

Control structures are core features of the PHP language that allow your script to respond differently to different inputs or situations. This could allow your script to give different responses based on user input, file contents, or some other data.

They start with a flowchart showing the basic idea behind how flow control structures work and provide a more "real world" example of a user login. It then goes through each of the control structure types, providing a simple explanation of what it does, where it's useful and code examples of it in action.