Create Numerically Indexed Arrays

This article details creating numerically indexed arrays so I will proceed to show you the few ways you can create your first (numerically indexed) array.

Creating a Numerically Indexed Array

php:


<?php
//  Method I
//  ========
  $name = array( 'Garth','Andrew','Scott' );

//  Method II
//  =========
  $name[] = 'Garth';
  $name[] = 'Andrew';
  $name[] = 'Scott';

//  Method III
//  ==========
  # theoretically speaking, you COULD even
  # create your arrays this way
  $name[2] = 'Garth';
  $name[4] = 'Andrew';
  $name[6] = 'Scott';

//  Method IV
//  =========
  # this is when you need to create an array
  # using a combination of the methods
  # described above.

  $name = array( 'Garth' );
  # you can even do some other php stuff here
  # and then go back to populating your
  # array...
  $name[] = 'Andrew';
  $name[($i+1)] = 'Scott';
?>


That's it! Using either method shown above, you will have a numerically indexed array named $name which will contain a set of 3 values. Now... that wasn't SO confusing, was it?

TOP

How old are you?

 Teenager

 20 something

 30 something

 40 something

 Over 50