Phpdynamic

PHP and MySQL Programming Guides, Tutorials, & Articles

Archive for November, 2009

What are Arrays?

NOV 30

Introduction to Arrays in PHP

In previous tutorials we explained the concept of variables, which are named memory locations used to store a single value or piece of data. In a way arrays are similar to variables, but instead of just storing an individual piece of data, they can store groups of related data. A list of e-mail addresses, names of employees, or a list of products, are just some examples of data that can be stored in an array. Essentially any data that can be grouped together can be stored in an array. Once your understand the concept of arrays, it will become impossible to program without them.

An array can consist of any number of elements, or in other words data, were each element is distinguished and referenced by a unique identifier called a key. Array elements by default have numerical keys which are indexed sequentially, but they can also be indexed by user defined keys. An array that is indexed by numbers is called a numerically indexed array while an array that is indexed by strings is called an associative index array.

Numerically Indexed Arrays

In a numerically indexed array each element is indexed sequentially by an integer starting from zero by default, were the key or index relates to the element’s position within the array. Below is a simple illustration of an array. Note, the resemblance between the arrangement of an array and a table. The first column is the unique index of the array element and the second column is the actual data value. Each subsequent row follows the same pattern.

array table

Read more…

Working with Forms in PHP – Part 2

NOV 18

Form Elements with Multiple Values

In the first part of this tutorial, we worked with input boxes and radio buttons, which only allow a single data value to be submitted per form element. We are not limited to single values, because HTML also allows form elements such as check-boxes and select-boxes that allow the user to choose multiple items simultaneously for a single form field, so we need a way to process them a little differently in PHP. Lets start with an example:

Read more…