PHP

Parses the value of the specified key in the array splice array returning a new array


Use environment: the talent network project has a resume privacy Settings, which has a filter keywords, only a certain enterprise in the company name contains one of the keywords, do not show the resume, of course, I have not done there, now is to do keywords added and deleted. Imagine: No matter how many resumes a person has, all resumes are set up with a modular keyword filter (mostly used by very few people, so it doesn’t matter and is easy to use in search), and then all the keywords are combined into a half-corner comma separated string. Problem: During display I converted the string into an array and then looped it out, but now I’m just deleting the specified keyword. Solution: Since it’s an array, there are values and keys, so I’ll pass the keys to the delete page and delete the value of the specified key. Problem: How to remove a specified key from an array? I only see filter, push, and push. I don’t see a built-in function that removes a specified key. This function, called array_splice, easily removes the value of the specified key and returns a new array Code snippet:

<?php
$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']);// Into an array
array_splice($key,$autoid,1);  // Deletes the specified key value
$key_secret=implode(",",$key);  // Convert to a string that is easy to store
?>

$autoid is the key for the current value passed in, and array_splice($key,$autoid,1) means to remove from the $key array, starting with $autoid, to remove a group

array_splice itself is a very powerful built-in function, can be used for array and string exchange, array and array exchange, do not understand the manual