Presentation is loading. Please wait.

Presentation is loading. Please wait.

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.

Similar presentations


Presentation on theme: "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."— Presentation transcript:

1 NUMERIC ARRAYS IN PHP BY SKYLAR NEILSON

2 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)

3 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

4 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

5 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

6 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”

7 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”

8 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…


Download ppt "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."

Similar presentations


Ads by Google