• My PHP Pages

    This is a complete and free PHP programming course for beginners. Everything you need to get started is set out in section one below.

Jun 20, 2013

Posted by Unknown
No comments | 12:04 AM

Today lession is how to work with PHP arrays. An array is a variable which can store number of values at once


<?php
$phones = array("nokia","sony","samsung");

echo "Phones : ".$phone[0].",".$phone[1]." and ".$phone[2];


?>

result - Phones : nokia , sony and samsung


We can count number of values in the array using count() function.


<?php
$phones = array("nokia","sony","samsung");

echo "Phones : ".$phone[0].",".$phone[1]." and ".$phone[2];

echo "<br/> Number of values in this array is : ".count($phones);
?>

result - Phones : nokia , sony and samsung
            Number of values in this array : 3


Lets create an Associative arrays

There is no much difference between associative array and normal array but when we work with normal arrays, we retrieve data using index number. but if we use associative array we can use name keys to retrieve data. 

Lets see how to create an associative array.



<?php

$age = array("kasun"=>50,"nimal"=>55,"dasun"=>57)

echo "kasun is : ".$age['kasun']."years old";
?>



0 comments :

Post a Comment