PHP Arrays
Submitted by admin on Tuesday, November 19, 2013 - 12:13.
An array is the same as variable except that it can store multiple values using an index key.
Here’s an example:
You can also directly assign a value into an array with its index key, example:
The above example is using number as an index key. You can also use named key to identify an array easily.
Consider the following example:
An associative array is very useful if you want to access your table’s record using a field name.
Example:
- <?php
- echo "The following are biblical name: " . names[0] . ", " . names[1] . ", " . names[2] . ", " . names[3] . ".";
- ?>
- <?php
- $names[0] = "John";
- $names[1] = "Peter";
- $names[2] = "Matthew";
- $names[3] = "Andrew";
- echo "The following are biblical name: " . names[0] . ", " . names[1] . ", " . names[2] . ", " . names[3] . ".";
- ?>
- <?php
- $name["John"] = 35;
- $name["Peter"] = 28;
- $name["Matthew"] = 31;
- $name["Andrew"] = 34;
- echo "John’s age is: " . $name["John"];
- ?>
- <?php
- echo $table["name"];
- echo $table["address"];
- ?>
Add new comment
- 445 views