Book Image

Beginning PHP

By : David Carr, Markus Gray
Book Image

Beginning PHP

By: David Carr, Markus Gray

Overview of this book

<p>PHP is the preferred server-side scripting language for tech giants such as Facebook, Wikipedia, and Tumblr despite full-stack JavaScript gaining popularity with upcoming developers. This is because PHP performs better when dealing with heavy computations on the back end. In this book, you’ll learn everything you need to get up and running with the latest version of PHP, including package management with tools such as composer, secure database operations, and a whole host of other best practices that will help you stay a step ahead of traditional programmers. </p><p> </p><p></p>
Table of Contents (12 chapters)
Beginning PHP
Contributors
Preface
Free Chapter
1
Getting Started with PHP
2
Arrays and Loops
Index

Chapter 2. Arrays and Loops

In the previous chapter, we covered variables and data types along with the different operators. We also covered how to control the flow of programs using conditionals. In this chapter, we will focus on how to store multiple values using arrays and how to control the flow using loops. The basic idea of an array is that it is a variable type, allowing one to store multiple items within a single container.

For example, if you wanted to store the names of all the employees working in a company under the same variable, an array would help you do that. Loops are used when we want to run the same block of code multiple times. This saves a lot of work for the developer by reusing the pre-defined code block. These two concepts are at the core of almost every PHP-based web application and website on the web today.

By the end of this chapter, you will be able to:

  • Implement one-dimensional and multidimensional arrays

  • Identify the difference between indexed and associative...