numeric arrays in php by skylar neilson. what are numeric arrays? they are arrays with a numeric...

8
NUMERIC ARRAYS IN PHP BY SKYL AR NEILS ON

Upload: calvin-poole

Post on 12-Jan-2016

213 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: NUMERIC ARRAYS IN PHP BY SKYLAR NEILSON. WHAT ARE NUMERIC ARRAYS? They are arrays with a numeric index and the values are stored and accessed in linear

NUMERIC A

RRAYS IN

PHP

BY

SK

YL A

R N

EI L

SO

N

Page 2: NUMERIC ARRAYS IN PHP BY SKYLAR NEILSON. WHAT ARE NUMERIC ARRAYS? They are arrays with a numeric index and the values are stored and accessed in linear

WHAT ARE NUMERIC ARRAYS?

They are arrays with a numeric index and the values are stored and accessed in linear fashion. The index, by default, always starts at “0” and continue on up the number line.

There are two methods to creating a numeric array

(see next slide for example methods)

Page 3: NUMERIC ARRAYS IN PHP BY SKYLAR NEILSON. WHAT ARE NUMERIC ARRAYS? They are arrays with a numeric index and the values are stored and accessed in linear

EXAMPLES OF NUMERIC ARRAYS

Method 1- One statement array

$numbers = array( 1, 2, 3, 4, 5);

Method 2-Multiple statements array

$numbers[0] = "one";

$numbers[1] = "two";

$numbers[2] = "three";

$numbers[3] = "four";

$numbers[4] = "five";

This is the name of the array

Page 4: NUMERIC ARRAYS IN PHP BY SKYLAR NEILSON. WHAT ARE NUMERIC ARRAYS? They are arrays with a numeric index and the values are stored and accessed in linear

EXAMPLES OF NUMERIC ARRAYS

Method 1- One statement array

$numbers = array( 1, 2, 3, 4, 5);

Method 2-Multiple statements array

$numbers[0] = "one";

$numbers[1] = "two";

$numbers[2] = "three";

$numbers[3] = "four";

$numbers[4] = "five";

These are the values

Page 5: NUMERIC ARRAYS IN PHP BY SKYLAR NEILSON. WHAT ARE NUMERIC ARRAYS? They are arrays with a numeric index and the values are stored and accessed in linear

EXAMPLES OF NUMERIC ARRAYS

Method 1- One statement array

$numbers = array( 1, 2, 3, 4, 5);

Method 2-Multiple statements array

$numbers[0] = "one";

$numbers[1] = "two";

$numbers[2] = "three";

$numbers[3] = "four";

$numbers[4] = "five";

These are places, they start at 0, not at 1

Page 6: NUMERIC ARRAYS IN PHP BY SKYLAR NEILSON. WHAT ARE NUMERIC ARRAYS? They are arrays with a numeric index and the values are stored and accessed in linear

TO VIEW ALL VALUES IN THE ARRAY

Use echo and the name of the array to display the array’s values

$numbers = array( 1, 2, 3, 4, 5);

echo “$numbers”

$numbers[0] = "one";

$numbers[1] = "two";

$numbers[2] = "three";

$numbers[3] = "four";

$numbers[4] = "five";

echo “$numbers”

Page 7: NUMERIC ARRAYS IN PHP BY SKYLAR NEILSON. WHAT ARE NUMERIC ARRAYS? They are arrays with a numeric index and the values are stored and accessed in linear

SINGLE STATEMENT ARRAYS

$numbers = array( 1, 2, 3, 4, 5);

To call the first place of the array you must use ‘0’, calling ‘0’ will show the first value which is ‘1’ and so forth

If you call location ‘4’ it will display “5”

If you call location ‘2’ if will display “3”

Page 8: NUMERIC ARRAYS IN PHP BY SKYLAR NEILSON. WHAT ARE NUMERIC ARRAYS? They are arrays with a numeric index and the values are stored and accessed in linear

MULTIPLE STATEMENTS ARRAY

$numbers[0] = "one";

$numbers[1] = "two";

$numbers[2] = "three";

$numbers[3] = "four";

$numbers[4] = "five";

With multiple statements array, to call the value you must input the desired place with the right number (the brackets show the location called and will display the number in quotes)

If you say get location ‘2’ it will display “three”

If you say get location ‘0’ it will display “one”

And so on…