0
Returns an array of the parameters. The parameters can be given an index with the => operator. Read the section on the array type for more information on what an array is.
返回参数的一列信息.参数可以通过 =>操作符来附值.请认真看这部分来了解array是何物!
Note:
array() is a language construct used to represent literal arrays, and not a regular function.
array()是一个构造函数,而不是一个普通函数.
Syntax "index => values", separated by commas, define index and values. index may be of type string or numeric. When index is omitted, an integer index is automatically generated, starting at 0. If index is an integer, next generated index will be the biggest integer index + 1. Note that when two identical index are defined, the last overwrite the first.
语法 "index => values",使用commas分开,定义索引和值.索引可以是 string类型或者numeric类型.当索引忽略时候,一个整数的索引自动产生,以0开始.如果索引是整数开始,下一个产生的索引将是比当前的索引+1.如果有两个相同的索引,后一个将覆盖前一个.
The following example demonstrates how to create a two-dimensional array, how to specify keys for associative arrays, and how to skip-and-continue numeric indices in normal arrays.
下面的例子告诉我们如何创建一个二维的array.
Example 142. array() example
Example 143. Automatic index with array()
will display:
(
[0] => 1
[1] => 1
[2] => 1
[3] => 13
[4] => 1
[8] => 1
[9] => 19
) ?>
This example creates a 1-based array.
其他人对array的补充说明:
here is the sort of "textbook" way to output the contents of an array which avoids using foreach() and allows you to index & iterate through the array as you see fit:
这是不使用foreach的方法去输出array内容的方法,可以通过控制索引或者遍历的方式.
a slightly better way to create large 2d arrays:
一种比较好的创建大型二维array的方法
Similarly to a comment by stlawson at sbcglobal dot net on this page:
http://www.php.net/basic-syntax.instruction-separation
It is usually advisable to define your arrays like this:
Note the comma after the last element - this is perfectly legal. Moreover,
it's best to add that last comma so that when you add new elements to the
array, you don't have to worry about adding a comma after what used to be
the last element.
一种操作array的方法
i tried to find a way to create BIG multidimensional-arrays. but the notes below only show the usage of it, or the creation of small arrays like $matrix=array('birne', 'apfel', 'beere');
for an online game, i use a big array (50x80) elements.
it's no fun, to write the declaration of it in the ordinary way.
here's my solution, to create an 2d-array, filled for example with raising numbers.
给array后面添加值的方法:
if there is a better way, plz send an email. i always want to learn more php!
Heres a simple yet intelligent way of setting an array, grabbing the values from the array using a loop.
How to print an arrray.
here's a nice short/lazy way to create an array:
I got tired of trying to find a function to add a entry to the "top"/index 0 to a array the i made a function for it.
The easiest way to "list" the values of either a normal 1 list array or a multi dimensional array is to use a foreach() clause.
Example for 1 dim array:
For multi dim array:
array_push() treats array as a stack, and pushes the passed variables onto the end of array. The length of array increases by the number of variables pushed. Has the same effect as:
$array[] = $var;
//使用这个方法为array后面添加一个数据$var 当然也可以使用array_push()
?>
repeated for each var.
Returns the new number of elements in the array.
Example 129. array_push() example
This is quite possibly the easiest way i've found to iterate through an array.
Just to correct example posted by "daevid at daevid dot com" on 14-Mar-2003 01:52.
array_merge renumber numeric keys, thus the key may not be mantained.
Try this code:
array_merge() merges the elements of two or more arrays together so that the values of one are appended to the end of the previous one. It returns the resulting array.
If the input arrays have the same string keys, then the later value for that key will overwrite the previous one. If, however, the arrays contain numeric keys, the later value will not overwrite the original value, but will be appended.
Example 123. array_merge() example
The $result is:
返回参数的一列信息.参数可以通过 =>操作符来附值.请认真看这部分来了解array是何物!
Note:
array() is a language construct used to represent literal arrays, and not a regular function.
array()是一个构造函数,而不是一个普通函数.
Syntax "index => values", separated by commas, define index and values. index may be of type string or numeric. When index is omitted, an integer index is automatically generated, starting at 0. If index is an integer, next generated index will be the biggest integer index + 1. Note that when two identical index are defined, the last overwrite the first.
语法 "index => values",使用commas分开,定义索引和值.索引可以是 string类型或者numeric类型.当索引忽略时候,一个整数的索引自动产生,以0开始.如果索引是整数开始,下一个产生的索引将是比当前的索引+1.如果有两个相同的索引,后一个将覆盖前一个.
The following example demonstrates how to create a two-dimensional array, how to specify keys for associative arrays, and how to skip-and-continue numeric indices in normal arrays.
下面的例子告诉我们如何创建一个二维的array.
Example 142. array() example
Example 143. Automatic index with array()
will display:
引用
(
[0] => 1
[1] => 1
[2] => 1
[3] => 13
[4] => 1
[8] => 1
[9] => 19
) ?>
引用
Note that index '3' is defined twice, and keep its final value of 13. Index 4 is defined after index 8, and next generated index (value 19) is 9, since biggest index was 8.
This example creates a 1-based array.
其他人对array的补充说明:
here is the sort of "textbook" way to output the contents of an array which avoids using foreach() and allows you to index & iterate through the array as you see fit:
这是不使用foreach的方法去输出array内容的方法,可以通过控制索引或者遍历的方式.
a slightly better way to create large 2d arrays:
一种比较好的创建大型二维array的方法
Similarly to a comment by stlawson at sbcglobal dot net on this page:
http://www.php.net/basic-syntax.instruction-separation
It is usually advisable to define your arrays like this:
Note the comma after the last element - this is perfectly legal. Moreover,
it's best to add that last comma so that when you add new elements to the
array, you don't have to worry about adding a comma after what used to be
the last element.
一种操作array的方法
i tried to find a way to create BIG multidimensional-arrays. but the notes below only show the usage of it, or the creation of small arrays like $matrix=array('birne', 'apfel', 'beere');
for an online game, i use a big array (50x80) elements.
it's no fun, to write the declaration of it in the ordinary way.
here's my solution, to create an 2d-array, filled for example with raising numbers.
给array后面添加值的方法:
if there is a better way, plz send an email. i always want to learn more php!
Heres a simple yet intelligent way of setting an array, grabbing the values from the array using a loop.
How to print an arrray.
here's a nice short/lazy way to create an array:
I got tired of trying to find a function to add a entry to the "top"/index 0 to a array the i made a function for it.
The easiest way to "list" the values of either a normal 1 list array or a multi dimensional array is to use a foreach() clause.
Example for 1 dim array:
For multi dim array:
array_push() treats array as a stack, and pushes the passed variables onto the end of array. The length of array increases by the number of variables pushed. Has the same effect as:
$array[] = $var;
//使用这个方法为array后面添加一个数据$var 当然也可以使用array_push()
?>
repeated for each var.
Returns the new number of elements in the array.
Example 129. array_push() example
This is quite possibly the easiest way i've found to iterate through an array.
Just to correct example posted by "daevid at daevid dot com" on 14-Mar-2003 01:52.
array_merge renumber numeric keys, thus the key may not be mantained.
Try this code:
array_merge() merges the elements of two or more arrays together so that the values of one are appended to the end of the previous one. It returns the resulting array.
If the input arrays have the same string keys, then the later value for that key will overwrite the previous one. If, however, the arrays contain numeric keys, the later value will not overwrite the original value, but will be appended.
Example 123. array_merge() example
The $result is:
引用
(
[color] => green
[0] => 2
[1] => 4
[2] => a
[3] => b
[shape] => trapezoid
[4] => 4
) ?>
[color] => green
[0] => 2
[1] => 4
[2] => a
[3] => b
[shape] => trapezoid
[4] => 4
) ?>
突然进入无限的迷茫......
How to use php array[ALL]


2007/04/28
12:19
5320



