Home php教程 php手册 解析array splice的移除数组中指定键的值,返回一个新的数组

解析array splice的移除数组中指定键的值,返回一个新的数组

Jun 06, 2016 pm 08:28 PM
array_splice

array_splice这个数组函数在w3school的解释是把数组中的一部分去掉并用其它值取代。所以我在做数组移除的时候没有考虑到用这个函数,或者因为从来没有用过

使用环境:人才网项目中有一个简历保密设置,其中有一个过滤关键词,服务器空间,只有某个企业的公司名中包含有其中的一个关键字,就不显示该份简历,当然,我还没有做到那里去,现在是要做关键词的增加删除。
设想:不管一个人有多少份简历,所有简历都设置成一模一样的关键词过滤(主要是用的人也很少,所以这样存储无所谓,而且在搜索使用中很方便),然后将所有关键词组成一个用半角逗号分隔的字符串。
难题:显示的时候我将字符串转化成数组然后再循环出来显示,但是我现在就是要删除指定的关键词。
解决方案:既然转化成了数组,香港服务器,那么有值就有键,我就将键传到删除页面去,删除指定键的值就好了嘛。
难题:怎么从数组中删除指定键值呢,我只看到了过滤、入栈、出栈,没有看到移除指定键值的内置函数。 
现在,这个函数已经现身了,它叫array_splice,用它可以轻易的移除指定键的值,然后返回一个新的数组
代码片断:

复制代码 代码如下:


$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']);//转化成数组
array_splice($key,$autoid,1);  //删除指定键值
$key_secret=implode(",",$key);  //转化成便于存储的字符串
?>


$autoid是传过来的当前值的键,array_splice($key,$autoid,1)的意思就是从$key的数组中,从$autoid开始移除,移除一组

array_splice本身是一个很强大的内置函数,可以用于数组与字符串的交换,数组与数组的交换,不懂看手册
,虚拟主机
Statement of this Website
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

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
2 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Hello Kitty Island Adventure: How To Get Giant Seeds
1 months ago By 尊渡假赌尊渡假赌尊渡假赌
Two Point Museum: All Exhibits And Where To Find Them
1 months ago By 尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)