PHP如何提取键和值,而不指数数组 [英] PHP how to extract the array of keys and values without index
问题描述
我想提取一个数组(与主要和放原始数组;值)。
之后我提取阵列,我要阵列的两个新的阵列(第一个数组只是键,另一个数组只是值),并没有这两个指数(见code为例)
//原数组
$阵列=阵列(
名1=> 500
NAME2=> 400
NAME3=高于300
NAME4=> 200
NAME5=大于100
); //提取物阵列后
$数组1 =阵列('名称1','名2','NAME3','NAME4','NAME5);
$数组2 =阵列(500,400,300,200,100); //不喜欢这个
// $ ARRAY1 =阵列(0 =>'NAME1',1 =>'NAME2',2 =>'NAME3',3 =>'NAME4',4 = GT;'NAME5);
// $数组2 =阵列(0 => 500,1 = GT; 400,2 = 300,3 = GT; 200,4 =大于100);
$ ARRAY1 = array_keys($数组);
$数组2 = array_values($数组);
好了,你可以在这里阅读 。
在计算机科学中,一个阵列或者干脆数组是一
数据结构包括元素集合的(价值或
变量),每个识别出的由至少一个数组索引或键即可。一个
数组存储使每个元件的位置可以被计算
由数学公式的索引记录。
块引用>I want to extract an array (original array with key&value). After I extract the array ,I want the two new arrays(first array is just keys,another array is just values)and both of arrays without index (see code example)
// original array $array = array( "name1"=>500 ,"name2"=>400 ,"name3"=>300 ,"name4"=>200 ,"name5"=>100 ); //after extract arrays $array1 = array('name1','name2','name3','name4','name5); $array2 = array(500,400,300,200,100); //not like this //$array1 = array(0=>'name1',1=>'name2',2=>'name3',3=>'name4',4=>'name5); //$array2 = array(0=>500,1=>400,2=?300,3=>200,4=>100);
解决方案$array1 = array_keys($array); $array2 = array_values($array);
well, you can read here.
In computer science, an array data structure or simply an array is a data structure consisting of a collection of elements (values or variables), each identified by at least one array index or key. An array is stored so that the position of each element can be computed from its index tuple by a mathematical formula.
这篇关于PHP如何提取键和值,而不指数数组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!