Get the App
SLTechnology News&Howtos  ›  Development  › 

How to use array_splice to remove the value of a specified key in an array and return a new array

Shulou Source: shulou.com Published: 2022-06-03 06:40:07 11月15日 Update

This article mainly introduces how to use array_splice to remove the value of the specified key in the array to return a new array, the article is very detailed, has a certain reference value, interested friends must read it!

Use environment: there is a resume confidentiality setting in the talent network project, in which there is a filtering keyword, and only one of the keywords in the company name of an enterprise will not be displayed. Of course, I haven't been there yet. Now it's time to add and delete keywords.

Imagine: no matter how many resumes a person has, all resumes are set to the same keyword filter (few people mainly use them, so it doesn't matter, and it's convenient to search). Then put all the keywords into a string separated by a half-width comma.

Conundrum: when displaying, I convert the string into an array and then loop it out to display, but now I just want to delete the specified keyword.

Solution: now that it has been converted into an array, then there is a key if there is a value, so I will pass the key to the delete page and delete the value of the specified key.

Conundrum: how to remove the specified key from the array? I only see filtering, going on and off the stack, but I don't see the built-in function to remove the specified key.

Now that this function is available, it is called array_splice, and you can easily remove the value of the specified key and return a new array.

Code snippet:

The copy code is as follows:

Tags: Array key keyword character string resume code function middle finger content article problem storage powerful exactly the same it doesn't matter individual talent talent network value Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno OPPO Reno Shulou Technology Redmi macOS Apple