Вся предоставленная на этом сервере информация собрана нами из разных источников. Если Вам кажется, что публикация каких-то документов нарушает чьи-либо авторские права, сообщите нам об этом.
PHP supports both scalar and associative arrays. In fact, there
is no difference between the two. You can create an array using
the list() or array()
functions, or you can explicitly set each array element value.
$a[0] = "abc";
$a[1] = "def";
$b["foo"] = 13;
You can also create an array by simply adding values to the
array. When you assign a value to an array variable using empty
brackets, the value will be added onto the end of the array.
In PHP3, the above will output This won't work:
Array[bar]. The string concatenation operator,
however, can be used to overcome this:
$a[3]['bar'] = 'Bob';
echo "This will work: " . $a[3][bar];
In PHP4, however, the whole problem may be circumvented by
enclosing the array reference (inside the string) in curly
braces:
$a[3]['bar'] = 'Bob';
echo "This will work: {$a[3][bar]}";
You can "fill up" multi-dimensional arrays in many ways, but the
trickiest one to understand is how to use the
array() command for associative arrays. These
two snippets of code fill up the one-dimensional array in the
same way: