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?

Does PHP's array() operate on arrays or objects?

WBOY
WBOYOriginal
2022-07-11 10:28:281652browse

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.)".

Does PHP's array() operate on arrays or objects?

The operating environment of this article: Windows 10 system, PHP version 8.1, Dell G3 computer

Does array() in php operate on arrays or objects?

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[&#39;Peter&#39;] . " years old.";
?>

Output result:

Does PHPs array() operate on arrays or objects?

##Example:

<?php
$cars=array("Volvo","BMW","Toyota");
echo "I like " . $cars[0] . ", " . $cars[1] . " and " . $cars[2] . ".";
?>

Output result:

Does PHPs array() operate on arrays or objects?

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!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn