本文介绍了PHP 将数组拆分为两个数组 - 键数组和值数组的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否有一种简单的方法可以将一个数组拆分为两个数组,一个由所有键组成,另一个由所有值组成?这将与 array_combine 的操作相反.是否有用于执行此类任务的内置功能?让我们使用一个示例数组:

Is there an easy way to split an array into two arrays, one consisting of all the keys and the other consisting of all the values? This would be a reverse to the action of array_combine. Is there an inbuilt function for doing such a task?Let's use an example array:

$array = array('Tiger' => 'Forest', 'Hippo' => 'River', 'Bird' => 'Sky');

是否有一个函数可以将上述数组拆分为:

Is there a function that will split the above array into:

$array_keys = array('Tiger', 'Hippo', 'Bird');
$array_values = array('Forest', 'River', 'Sky');

推荐答案

有两个函数叫做 array_keysarray_values:

There are two functions called array_keys and array_values:

$array_keys = array_keys($array);
$array_values = array_values($array);

这篇关于PHP 将数组拆分为两个数组 - 键数组和值数组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-14 11:28