Home  >  Article  >  Backend Development  >  How to remove key names from php array

How to remove key names from php array

藏色散人
藏色散人Original
2020-07-22 09:47:574174browse

How to remove key names from PHP arrays: first define an array with key names; then use the "array_values" method to take out the array with key names; finally use the "array_merge" method to merge into a new array. .

How to remove key names from php array

PHP removes key names and merges arrays

Define an array with key names, as shown in the figure.

Recommended: "PHP Tutorial"

How to remove key names from php array

Define another two similar arrays, key names They are all different.

How to remove key names from php array

To merge arrays, we just use the array_merge method to merge.

How to remove key names from php array

After merging, we output the results.

How to remove key names from php array

It can be seen from the results that if you merge directly like this, the key names of the array will also be merged.

How to remove key names from php array

Therefore, before merging, we need to take out the array with key names first. You can use the array_values ​​method, which will discard the original key names. of.

How to remove key names from php array

After modification, re-run, you can see that the key names of the original array are gone. The resulting new array uses numbers as keys, starting from serial number 0.

How to remove key names from php array

The above is the detailed content of How to remove key names from php array. 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