O'Reilly logo

PHP for Teens by Maneesh Sethi

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Creating an Array

To create an array, you need several elements.

array() Language Construct

Use the array()language construct, which is very similar to a function. You call array() and the return value is equal to the new array. Therefore, whatever variable you set as equal to the result of array()becomes an array. For example, take a look at the following:

$newarray = array();

Your new array will be stored in the variable $newarray. Of course, the problem we have now is that this array is blank! We have to create items in the array. Before we do this, let me show you how to reference items in an array.

Reference Items

Array items have two parts: a key and a value. A key is basically the location of the variable, and the value is what is stored ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required