value,key=>value,key=>value,etc.)"."/> value,key=>value,key=>value,etc.)".">
Home >Backend Development >PHP Problem >Does PHP's array() operate on arrays or objects?
In PHP, array() operates on arrays and is a function that allows operations on arrays. The function of this function is to create arrays; PHP supports single-dimensional and multi-dimensional arrays, and also provides database query results. Function to construct an array, the syntax is "array(value1,value2,value3,etc.)" or "array(key=>value,key=>value,key=>value,etc.)".
The operating environment of this article: Windows 10 system, PHP version 8.1, Dell G3 computer
array() function is used to create an array.
PHP array is a function that allows operations on arrays. PHP supports single-dimensional and multi-dimensional arrays. It also provides functions for constructing arrays using database query results.
In PHP, there are three types of arrays:
Numeric Array - Array with numeric ID keys
Associative array - an array with specified keys, each key associated with a value
Multidimensional array - an array containing one or more arrays
Grammar
The syntax of numerical array:
array(value1,value2,value3,etc.);
The syntax of associative array:
array(key=>value,key=>value,key=>value,etc.);
The parameters are expressed as follows:
key specifies the key name (numeric value or string).
value specifies the key value.
The example is as follows:
<?php $age=array("Peter"=>"35","Ben"=>"37","Joe"=>"43"); echo "Peter is " . $age['Peter'] . " years old."; ?>
Output result:
##Example:<?php $cars=array("Volvo","BMW","Toyota"); echo "I like " . $cars[0] . ", " . $cars[1] . " and " . $cars[2] . "."; ?>Output result: Recommended study: "
PHP Video Tutorial"
The above is the detailed content of Does PHP's array() operate on arrays or objects?. For more information, please follow other related articles on the PHP Chinese website!