0
How does one declare an array .. i know dersz no declaration in php just want more insight on array in php
php
3 Réponses
0
u can declare an array like dis in php
$myarr = array();
note d above is an empty array.
assign values to d array like dis
$myarr[]= 'maths';
$myarr[]= 'english';
$myarr[] = 'chemistry';
access d values like dis
echo $myarr[0];
prints out maths cuz it is d first item inside d array and arrays are indexed from 0.
D above example is an indexed array.
0
thanks
- 1
Numberic array
$a = Array (0, 1, 2);
or
$a = [0, 1, 2];
Associative Array
$a = Array ("foo" => "bar", "bar" => "baz");
or
$a ["foo" => "bar", "bar" => "baz"];