Tutorial PHP Arrays

An array stores multiple values in one single variable:

<?php
$cars=array(“red”,”blue”,”blue”);
echo “I like ” . $cars[0] . “, ” . $cars[1] . ” and ” . $cars[2] . “.”;
?>

What is an Array?

An array is a special variable, which can hold more than one value at a time.

If you have a list of items (a list of car names, for example), storing the cars in single variables could look like this:

$cars1=”red”;
$cars2=”blue”;
$cars3=”blue”;

Create an Array in PHP

In PHP, the array() function is used to create an array:

array();

Get The Length of an Array – The count() Function

<?php
$cars=array(“Volvo”,”BMW”,”Toyota”);
echo count($cars);
?>
3starinfo.com

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s