PDA

View Full Version : Basic PHP Tutorial - 5



ctt1010
11-01-2014, 02:06 PM
In this tutorial we will be learning about arrays. In PHP, arrays are used to store multiple values in a single variable. For example, we could have a fruits array, and it could store apple, banana, orange and pear.

This is what an array looks like :



<?php
$fruits = array("Apple","Banana","Orange","Pear");
?>


We could print out an item in an array, such as the first one which is Apple. For this we will use :



<?php
echo $fruits[0];
?>


Now, you may think this prints out nothing, but it actually prints out Apple. In an array, it starts with 0, and counts up. For example if you wanted to echo $fruits[1]; , that would print out Banana.