Get the App
SLTechnology News&Howtos  ›  Development  › 

How php removes numeric indexes from arrays

Shulou Source: shulou.com Published: 2022-06-03 10:38:36 10月02日 Update

What this article shares with you is about how php removes the digital index in the array. The editor thinks it is very practical, so I share it with you to learn. I hope you can get something after reading this article.

Removal method: 1, define a string array "$keys", the elements of the array are strings, the number of elements is the same as the array "$arr" that needs to be processed; 2, use the "array_combine ($keys,$arr)" statement to remove the number index in the "$arr" array, and convert the number index into a string index.

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

In php, you can use the array_combine () function to remove the numeric index from the array and turn the numeric index into a string index.

Output result:

Let's take a look at the array_combine () function.

The array_combine () function creates a new array by merging two arrays, one of which is the key name and the other is the key value.

Syntax:

Array_combine ($keys,$values)

The element in the $keys array serves as the key name of the new array, and the element of the $values array serves as the key value of the new array.

It is important to note, however, that when creating an array using the array_combine () function, the number of elements in the $keys array and the $values array must be the same, so that the key name and key value correspond one to one, otherwise an error will be reported and FALSE will be returned.

This is how php removes the digital index from the array. The editor believes that there are some knowledge points that we may see or use in our daily work. I hope you can learn more from this article. For more details, please follow the industry information channel.

Tags: Array index element number function character string number more knowledge article practical same consistent one-to-one correspondence two that is work meeting tutorial article Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno MariaDB Huawei Microsoft OPPO Reno Linux