Last updated on November 18th, 2015 at 03:58 am
Arrays in PHP is very simple and if you have a programming background you can easily identify Numeric Arrays and Associative array difference. Here I am showing both with an example.
<?php $employee_names[0] = "Raj"; $employee_names[1] = "Thomas"; $employee_names[2] = "Anil"; echo "The first employee's name is ".$employee_names[0]; echo "<br>"; echo "The second employee's name is ".$employee_names[1]; echo "<br>"; echo "The third employee's name is ".$employee_names[2]; ?>
In the above example we have added couple of names for employee_names array and call each name according to the position.
Associative Array
<?php $employee_names = array("arun" => "Owner", "Jess" => "Manager", "Thomas" => "Peon"); echo "Matt is the ".$employee_names["Jess"]; ?>
In this example we have associated each name to a value and when we cann employee_names[‘Jess’] it shows value as Manager.
Very simple array tutorial