Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Non-playable array in php array

2025-02-22 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)05/31 Report--

This article mainly introduces the php array can not put the array of related knowledge, the content is detailed and easy to understand, the operation is simple and fast, has a certain reference value, I believe you can read this php array article can not put the array will have a harvest, let's take a look at it.

You can put an array in an php array. PHP arrays can store all types of data, including, of course, the array itself; if the elements in one array are another array, it forms an array containing an array, that is, a multi-dimensional array. The different dimensions of the array indicate that several subscripts (indexes) are required to obtain the corresponding array elements, such as two subscripts for a two-dimensional array.

Operating environment of this tutorial: windows7 system, PHP7.1 version, DELL G3 computer

You can put an array in an php array.

Array is one of the most important data types in PHP, and it is widely used in PHP. Because PHP is a programming language with weak data types, array variables in PHP can store any number of data, any type of data, and can realize the functions of data structures such as heap, stack, queue and so on in other strong data types.

Arrays in PHP can store all types of data, including, of course, the array itself. If the elements in one array are another array, it forms an array containing an array, that is, a multi-dimensional array:

Two-dimensional array

Three-dimensional array

Four-dimensional array

.

However, when the array exceeds three dimensions, the readability is greatly reduced and it is not easy to manage.

Let's take a look at how to define a multidimensional array:

1. Define two-dimensional array

A two-dimensional array is declared in the same way as an one-dimensional array, except that one or more elements in the array are also declared as an array. There are also two ways to declare a two-dimensional array by directly assigning values to the array elements and using the array () function.

1) directly assign values to array elements

We can create and initialize a two-dimensional array in a format such as "$array variable name [row subscript] [column subscript] = value;"

Output result:

If the row subscript and column subscript of a two-dimensional array can be empty (that is, no specific index value is specified), the default is a numeric index, while the index value increases sequentially from 0 by default.

Example 1: column subscript is empty

Output result:

Example 2: line subscript is empty

Output result:

Example 3: both Row subscript and column subscript are empty

Output result:

2), use the array () function

Declaring a two-dimensional array using the array () function is similar to declaring an one-dimensional array.

Indexed array

Output result:

Associative array

Example 1:

Output result:

Example 2:

Output result:

Extensions: getting elements in a two-dimensional array

You only need to indicate the subscript of each dimension.

Output result:

Note: different dimensions of the array indicate that we need to use several subscripts (indexes) to get the corresponding array elements, such as two subscripts for a two-dimensional array, three for a three-dimensional array, and so on.

2. Creation of multidimensional array

With reference to a two-dimensional array, you can easily create a three-dimensional array, a four-dimensional array, or other higher-dimensional arrays. An example of defining a 3D array is as follows:

Output result:

This is the end of the article on "whether or not to put an array in an php array". Thank you for reading! I believe you all have a certain understanding of the knowledge of "whether or not to put arrays in the php array". If you want to learn more, you are welcome to follow the industry information channel.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report