Home > Backend Development > PHP Problem > Does PHP's array() operate on arrays or objects?

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

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
Release: 2023-03-16 14:58:01
Original
1690 people have browsed it

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.);
Copy after login

The syntax of associative array:

array(key=>value,key=>value,key=>value,etc.);
Copy after login

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.";
?>
Copy after login

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] . ".";
?>
Copy after login
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!

Related labels:
php
source:php.cn
Statement of this Website
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
Latest Issues
php data acquisition?
From 1970-01-01 08:00:00
0
0
0
PHP extension intl
From 1970-01-01 08:00:00
0
0
0
How to learn php well
From 1970-01-01 08:00:00
0
0
0
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template