Get the App
SLTechnology News&Howtos  ›  Development  › 

Types and instance usage of php arrays

Shulou Source: shulou.com Published: 2022-06-03 19:04:01 10月02日 Update

This article focuses on "the types and instance usage of php arrays". Interested friends may wish to have a look at it. The method introduced in this paper is simple, fast and practical. Let's let the editor take you to learn the type and instance usage of php array.

An array is a special variable that can store multiple values in a single variable. Arrays are often used in php, and we can use array () to create a new array.

$arr=array ("foo" = > "bar", 12 = > TRUE)

Echo$arr ["foo"]; / / output: bar

Echo$arr [12]; / / output: 1

As you can see from the example, the array includes key names and values, "foo" and 12 are called key names (key), and "bar" and TRUE are corresponding values. Array entities contain both a key name and a value.

In this array, there are two types:

$arr ["foo"]: value is "bar", string type

$arr [12]: value is TRUE, Boolean

In PHP, there are three types of arrays:

1. Numerical array

Numeric arrays are arrays with numeric ID keys. The following array is an array of numbers. The key name of an array is an array.

$arr=array (0 = > 'ma',1= >' nong',2= > 'jiao',3= >' cheng')

two。 Associative array

An associative array is an array that uses the specified key that you assign to the array.

There are two ways to create associative arrays:

$age=array ("Peter" = > "35", "Ben" = > "37", "Joe" = > "43")

Or

$age=array ()

$age ['Peter'] = "35"

$age ['Ben'] = "37"

$age ['Joe'] = "43"

3. Multidimensional array

The value in one array can be another array, and the value of another array can also be an array. In this way, we can create a 2D or 3D array:

At this point, I believe you have a deeper understanding of "php array types and instance usage". You might as well do it in practice. Here is the website, more related content can enter the relevant channels to inquire, follow us, continue to learn!

Tags: Array type instance numerical value association content variable method learning output practical deeper special example interest single name multiple character string Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Redmi Xiaomi Shulou Technology NVidia vpn