Home >Backend Development >PHP Tutorial >Parse array splice to remove the value of the specified key in the array and return a new array_PHP tutorial

Parse array splice to remove the value of the specified key in the array and return a new array_PHP tutorial

WBOY
WBOYOriginal
2016-07-21 15:01:04813browse

Usage environment: There is a resume confidentiality setting in the talent network project, which has a filter keyword. Only if the company name of a certain company contains one of the keywords, the resume will not be displayed. Of course , I haven’t gone there yet, now I need to add and delete keywords.
Imagine: No matter how many resumes a person has, all resumes are set to the same keyword filtering (mainly because there are very few people using them, so it doesn’t matter if stored like this, and it is easy to use when searching) Convenient), and then form all the keywords into a string separated by half-width commas.
Problem: When displaying, I convert the string into an array and then loop it out for display, but now I want to delete the specified keyword.
Solution: Since it is converted into an array, then if there is a value, there will be a key. I will pass the key to the delete page and delete the value of the specified key. .
Problem: How to delete the specified key value from the array? I only saw filtering, pushing, and popping, but not the built-in functions for removing the specified key value.
Now, this function has appeared, it is called array_splice, you can use it to easily remove the value of the specified key, and then return a new array
Code snippet:

Copy code 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 the specified key value
$key_secret=implode(",",$key); //Convert to an array for easy storage The string
?>

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

array_splice itself is a very powerful built-in function, which can be used to exchange arrays and strings, arrays and arrays, and do not understand the manual

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/328030.htmlTechArticleUsage environment: There is a resume confidentiality setting in the talent network project, which has a filter keyword, only a certain company If the company name contains one of the keywords, the copy will not be displayed...
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