Php Tutorial – CHAPTER 5: How to make arrays in PHP.


Arrays are very important because let you create similar variables that
can be accessed without any complication. The positive of arrays is
that each element of an array has a unique ID that helps you to
identify it so easy. We are going to see three different examples about
arrays. There are numeric arrays, associative where each ID is
associated with a value and multidimensional array. In this tutorial we
are going to see only the first two type of arrays. The first example
we are going to evaluate corresponds to the numerical array.

<Html>
<head>
<title> IT IS A PHP SCRIPT BASED ON ARRAYS </title>
</head>
<body>
<span style="color: #ff0000;"><?php
$names[0] = "Hector";
$names[1] = "Nicolas";
$names[2] = "Suero";
echo $names[1] . " and " . $names[2] .
" are ". $names[0] . "'s brothers";
?></span>
</body>
</html>


The output of this script should be “Nicolas and Suero are Hector’s
brothers”. The next example will show how to define an associative
array.

<Html>
<head>
<title> IT IS A PHP SCRIPT BASED ON ARRAYS </title>
</head>
<body>
<span style="color: #ff0000;"><?php
$ages['Hector'] = "32";
$ages['Nicolas'] = "30";
$ages['Suero'] = "34";
echo "Hector is " . $ages['Hector'] . " years old.";
?></span>
</body>
</html>


The output of this script should be “Hector is 32 years old”.

You can leave a response, or trackback from your own site.

Leave a Reply

You must be logged in to post a comment.