dvcphp
asked on
Difference between array,list and map
HI Experts,
I want to know the difference between arrays,list and map and when is best to use them.
Thanks.
I want to know the difference between arrays,list and map and when is best to use them.
Thanks.
ASKER
Thanks Genius but I am still confused as to when to use one over the other.
The most cases - you use array, basicaly it depends on what you want to do.
Let's make examples:
Let's make examples:
<?php
// lets's make an array
$a = array(1, 2, 3);
// show me the array
print_r($a);
// let's make a list
list($first, $second, $third) = $a;
// list is like an array keys, but you can acces them with
// variable name like $first, not with $a[0]
echo $first;
?>
Or more complete one:
<?php
function addone($n)
{
return($n + 1);
}
// lets's make an array
$a = array(1, 2, 3);
// show me the array
print_r($a);
// let's make a list
list($first, $second, $third) = $a;
// list is like an array keys, but you can acces them with
// variable name like $first, not with $a[0]
echo $first;
$aa = array_map("addone", $a);
print_r($aa);
?>
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thank you.You explained it so well.Easy to understand.Thanks again.
Thanks. If any further questions, feel free to ask here.
http://pl2.php.net/manual/en/function.array.php
http://www.php.net/manual/en/function.list.php
http://php.net/manual/en/function.array-map.php