Friday, February 4, 2011

How to get value from array-PHP

Assalamu'alaikum dan selamat sejahtera

So,as previous post,i already give the PHP script ryte?so,this post,we will discuss on that script.Here is the script

<?PHP

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

for ($start; $start < 11; $start++) {
$answer[$start] = $start * $times;
print (" answer = " . $answer[$start] . "<BR>");

}

?>:

So,just focus on this line:

$answer[$start] = $start * $times;
print (" answer = " . $answer[$start] . "<BR>");

As $start=1,then it will be look like this : $answer[$start]=$answer[1] and then we assign the value in the array,like this:

$answer[1] = 1 * $times;

and then,to print or get the value from the array,we just need print($answer[1]); ,as in our case,this line below will get the value from the array:

print (" answer = " . $answer[1] . "<BR>");

after that it will loop again ,and $start will update and it's value will be 2.

Instead use number to get the value from array.we also can use text,like this:

$group = array();

$group["alpha"]="Team One";
$group["beta"]="Team Backup";

and to get the value:

print($group["alpha"]);

that all for this post.


N/NOTE:any confusing?

No comments:

Post a Comment