Creating an Array: Difference between revisions
Content added Content deleted
(→Groovy: Delete.) |
(→PHP: Delete.) |
||
Line 562: | Line 562: | ||
# d |
# d |
||
</lang> |
</lang> |
||
==[[PHP]]== |
|||
For a single dimension array with 10 elements: |
|||
<lang php> $array = array(1, 2, 3, 4, 5, 6, 7, 8, 9, 10) //$array[3] == 3 |
|||
$array = array("a", "b", "c", "d", "e", "f", "g", "h", "i", "j") //$array[3] == "c"</lang> |
|||
For a multi-dimension array: |
|||
<lang php> $array = array( |
|||
array(0, 0, 0, 0, 0, 0), |
|||
array(1, 1, 1, 1, 1, 1), |
|||
array(2, 2, 2, 2, 2, 2), |
|||
array(3, 3, 3, 3, 3, 3) |
|||
); |
|||
#You would call the array by this code. This will call the 3rd 1 on the second list |
|||
echo $array[1][3];</lang> |
|||
More: |
|||
<lang php><?php |
|||
$array = array(); /* Blank Array */ |
|||
$array[] = "Moo"; /* Sticks Moo in the next index */ |
|||
$array2 = array(1 => "A", 2=> "B", 3=>"C", 4=>"Moo"); /* Creates an Array with Values */ |
|||
print_r($array); /* Array(0=>"Moo") */ |
|||
print_r($array2); |
|||
/* |
|||
Array( |
|||
1 => A |
|||
2 => B |
|||
3 => C |
|||
4 => Moo |
|||
*/ |
|||
print($array2[5]); // Undefined Index |
|||
?></lang> |
|||
==[[Pike]]== |
==[[Pike]]== |