PHP Array

Why need Array?
An array is a special variable,Suppose we want to store 100 data item. So we need 100 different variable. So this is very typical work for programmer to manage 100 different variable.To overcome this problem we create a special type variable known as array.

  • Suppose we want to store 100 data item. So we need 100 different variable. So this is very
  • typical work for programmer to manage 100 different variable.To overcome this problem we
  • create a special type variable known as array.

What is an Array:-

  • array is a special type of variable that store one more values in one single variable
  • each element in the array has its own index.
  • In PHP, there are three kind of arrays:

Type of PHP array

  • Numeric array – An array with a numeric index starting 0,1 etc.
  • Associative array – An array with a string index you can start like sun,mon,tue etc.
  • Multidimensional array – An array containing one or more arrays

How to create array ?.
No 1. we can create an array by array function.

<?php 
$data=array("Sun","Mon","Tue","Wed"); 
?>

No 2. we can create each array element directly.

<?php
 $data[0]="Sun"; $data[1]="Mon"; $data[2]="Tue"; $data[3]="Sun"; 
?>

Numeric Arrays.
A numeric array stores each array element with a numeric index. In the following example the index are automatically assigned (index starts at 0):
Example

<? php
$data=array("Sun","Mon","Tue","Wed");
for($i=0;$i<4;$i++)
   { 
   echo $data[$i]." ";
   } 
?>

Output: Sun Mon Tue Web

Associative Array
An associative array, we can assign index value for each array element

<? php
$data=array("one"=>12,"two"=>34,"three"=>56); 
foreach ($data as $value)
     { 
      echo $value . " "; 
     }
 ?>

Output:- 12 34 56

NOTE  foreach loop is basically for accessing each array element.

Multidimensional Arrays
We mantain array inside array

<html>
<head>
<title>Two dimensional array</title>
</head>
<body bgcolor=white>
<h3>Two dimensional array</h3><br>
<table border="1">
<?php
$x=array
(
array(11,22,33),
array(44,55,66),
array(77,88,99)
);
for ($k=0;$k<3;$k++)
{
print "<tr>";
for ($j=0;$j<3;$j++)
{
echo "<td>".$x[$k][$j]."</td>";
}
print "</tr>";
}
?>
</table>
</body>
</html>

What print_r() function
print_r() function is useful for displaying the contents of an array element.
Example

<?php
   $data=array("Sun","Mon","Tue","Wed");
   print_r($data);
?>

Output: Array ( [0] => Sun [1] => Mon [2] => Tue [3] => Wed )

free gay porn
How to Dress Well When Overweight
porno the way outline originally from jcpenney

About The Grades Of Replica Designer Handbags
cartoon porn 27 year old Vanessa

Good Color Combinations for Clothes
xhamster footjoy closeout lopro placed

Kate Middleton Makes Daring Fashion Statement at Military Awards
youjizz the particular 10 most extreme retailers to purchase viewed sex

10 Louis Vuitton Slim Lambskin Gold Clutch
youjizz might make you think about a house in a cold country

Evergreen Fashion Tips That Work
porno Pier 59 was once again another West side favorite for many designers

The Muffin Top Wags the Finger
click jogos has three built in Maiden circuits

How to Tell if Axl Rose is Your Real Dad
miranda lambert weight loss He later claimed to have simply found it lying around
This entry was posted in   PHP.
Bookmark the   permalink.

Admin has written 171 articles