The array() function in PHP creates an array.
Array is of three types in PHP.
Indexed arrays − It is an array with numeric index
Associative arrays − It is an array with named keys
立即学习“PHP免费学习笔记(深入)”;
Multidimensional arrays − It is an array that have one or more arrays
Syntax
- // array with numeric index i.e. Indexed arraysarray(value1,value2...);// array with named keys i.e. associative arraysarray(key1 => value1, key2 => value2...)
登录后复制
Parameters
value − Set the value.
key − Set the key.
Return
The array() function returns an array of the parameters.
The following is an example of indexed arrays.
Example
Live Demo
- <?php $products = array("Electronics","Clothing","Accessories", "Footwear");$len = count($products);for($i = 0;$i<$len;$i++) { echo $products[$i]; echo "
";}?>
登录后复制
输出
- ElectronicsClothingAccessoriesFootwear
登录后复制
The following is an example of associative arrays.
Example
Live Demo
- "1","Cricket"=>"2");foreach($rank as $mykey=>$myvalue) { echo "Key = " . $mykey . ", Value = " . $myvalue; echo "
";}?>
登录后复制
输出
- Key = Football, Value = 1Key = Cricket, Value = 2
登录后复制
以上就是PHP中的array()函数的详细内容,更多请关注【创想鸟】其它相关文章!
声明:本站所有文章,如无特殊说明或标注,均为本站原创发布。任何个人或组织,在未征得本站同意时,禁止复制、盗用、采集、发布本站内容到任何网站、书籍等各类媒体平台。如若本站内容侵犯了原著者的合法权益,可联系我们进行处理。