Friday, February 4, 2011

Array-PHP

Assalamu'alaikum and selamat sejahtera

Okey,for this post,we will learn the array.What is array?click here for more.So,first of all i show to you on how declare the array in PHP.

the Declaration:

                  $Group = array( );

So,$Group is because i named it,well you can put any variable's name that you like.But,the important is,$Group already be an array because of "=array()".So,to assign the value to the array,look at this example below :

$Group = array();

$Group[]="Eagle";
$
Group[]="Alpha";
$
Group[]="Beta";
$
Group[]="Charlie";

beside we also can do like this:
 
 $Group = array("Eagle","Alpha","Beta","Charlie");

okey,as we assign this,PHP will assign this values to be like this:

$Group[0]=Eagle
$Group[1]=Alpha
$Group[2]=Beta
$Group[3]=Charlie

but,i want to be like this:

$Group[1]=Eagle
$Group[2]=Alpha
$Group[3]=Beta
$Group[4]=Charlie

well,its look common ryte?as usual,when we start to count ,we always start with one ryte?so,to make like this,follow this code below:

$Group = array();

$Group[1]="Eagle";
$
Group[2]="Alpha";
$
Group[3]="Beta";
$
Group[4]="Charlie";

or

 $Group = array(1=>"Eagle",2=>"Alpha",3=>"Beta",4=>"Charlie");

one more thing,if you want assign number instead of number,well here is the code:

 $Group = array(12,34,65);

or

$Group = array();

$Group[]=22;
$
Group[]=45;

so,we do not need the double quote,just straight away type what number that do you want to assign.To study more on the array.study this script:


<html>
<head>
<title>Array</title>
<?PHP

$start = 1;
$times = 2;
$answer = array();

for ($start; $start < 11; $start++) {
$answer[$start] = $start * $times;

print (" answer = " . $answer[$start] . "<BR>");
}
?>
</head>
<body>
</body>
</html>


N/NOTE:so far.....okay?

No comments:

Post a Comment