Parse the arraysplice to remove the specified key value from the array and return a new array _ php tip

Source: Internet
Author: User
The array_splice array function in w3school is used to remove part of the array and replace it with other values. So I didn't take this function into account when removing arrays, or because I have never used this function. Environment:The talent network project has a resume confidentiality setting. one of the keywords is a filter keyword. only one of the keywords in the company name of an enterprise does not display this resume. of course, I have not done so yet. now I want to add and delete keywords.
Imagine:No matter how many resumes a person has, all resumes are set to the same keyword filter (mainly used by few people, so this storage does not matter, and it is very convenient to use in search ), then, all the keywords form a string separated by commas.
Difficulties:When it is displayed, I convert the string into an array and then recycle it for display, but now I want to delete the specified keyword.
Solution:Since it is converted into an array, there is a key for the value, and I will upload the key to the delete page, just delete the value of the specified key.
Difficulties:How can I delete a specified key value from an array? I only see filtering, inbound, and outbound, but not the built-in function for removing the specified key value.
Now, this function has appeared. it is called array_splice. it can be used to easily remove the value of a specified key and then return a new array.
Code snippet:

The code is as follows:


$ SQL = "";
$ SQL. = "SELECT key_secret FROM". T _. "resume_relation_xuyinjie ";
$ SQL. = "WHERE 1 = 1 ";
$ SQL. = "AND userid = '". $ userid ."'";
$ Result = @ mysql_query ($ SQL) or die ('#41 #');
$ Row = @ mysql_fetch_array ($ result, MYSQL_ASSOC );
$ Key = explode (",", $ row ['key _ secret']); // convert to an array
Array_splice ($ key, $ autoid, 1); // delete a specified key value
$ Key_secret = implode (",", $ key); // Convert it to a string that is easy to store
?>


$ Autoid is the key of the passed current value. array_splice ($ key, $ autoid, 1) means to remove a group from the $ key array, starting from $ autoid

Array_splice is a powerful built-in function that can be used to exchange arrays and strings.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.