Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/289.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/user-interface/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
PHP:类似拼接的多索引数组删除/提取_Php - Fatal编程技术网

PHP:类似拼接的多索引数组删除/提取

PHP:类似拼接的多索引数组删除/提取,php,Php,是否有一个本机函数从数组中删除多个索引,然后返回源数组而不删除对象,反之亦然,以便在删除其余索引时只保留所需的索引 例如: $source = array('index1' => 1, 'index2' => 2, 'index3' => 3, 'index4' => 4); json_encode( array_extract( $source, array('index2','index4'))); // returns array('index2' => 2,

是否有一个本机函数从数组中删除多个索引,然后返回源数组而不删除对象,反之亦然,以便在删除其余索引时只保留所需的索引

例如:

$source = array('index1' => 1, 'index2' => 2, 'index3' => 3, 'index4' => 4);
json_encode( array_extract( $source, array('index2','index4'))); // returns array('index2' => 2, 'index4' => 4);
或:


不,因为有一个小问题,第一个数组包含键,第二个数组包含值。没有任何功能可以实现你想要的


有多个函数,array\u intersect、array\u diff、array\u intersect\u key、array\u diff\u key..但它们都需要匹配的数组。

我想我必须写我自己的助手了。。。
json_encode( array_except( $source, array('index1','index4'))); // returns array('index2' => 2, 'index3' => 3);