Php 如何获得具有相应键的数组的结果?
我排除了另一个问题,我解释错了一切,我希望这是更具体的 我看到了类似的问题,但这个案例有点特别 我需要为我给出的数组的每个值返回结果及其相应的键([264]、[265]等等) 我有这个阵列:Php 如何获得具有相应键的数组的结果?,php,arrays,Php,Arrays,我排除了另一个问题,我解释错了一切,我希望这是更具体的 我看到了类似的问题,但这个案例有点特别 我需要为我给出的数组的每个值返回结果及其相应的键([264]、[265]等等) 我有这个阵列: array(2) { [264]=> string(38) "64,74,103,102,101,100,23,13,3,89,88,87" //the value that I need to pass as a parameter [265]=> string(29)
array(2) {
[264]=>
string(38) "64,74,103,102,101,100,23,13,3,89,88,87" //the value that I need to pass as a parameter
[265]=>
string(29) "65,95,96,97,83,84,88,62,54,44" //the value that I need to pass as a parameter
}
我的职能:
function ArrayData($id){
foreach($id as $singleId){
$Data[][key($id)] = getData($singleId); //here I pass the value as parameter
}
}
/**
* get the result data
*
* @return {array} $id
*/
function getData($singleId){
$result = fetchData($singleId); //here i get the result of the value
$decode = json_decode($result, true);
return $decode;
}
我的职能结果:
array(2) {
[0]=>
array(1) {
[264]=>
array(11) {
[0]=>
array(5) {
["id"]=>
string(2) "64"
["concepto"]=>
string(27) "IIBB Contribuyentes Locales"
["impuesto"]=>
string(10) "Anticipo10"
["agencia"]=>
string(4) "ARBA"
["vencimiento_del_mes"]=>
string(10) "2017-11-21"
}
}
}
[1]=>
array(1) {
[264]=> //[this has to be 265]
array(5) {
[0]=>
array(5) {
["id"]=>
string(2) "65"
["concepto"]=>
string(27) "IIBB Contribuyentes Locales"
["impuesto"]=>
string(10) "Anticipo10"
["agencia"]=>
string(4) "ARBA"
["vencimiento_del_mes"]=>
string(10) "2017-11-22"
}
}
}
}
该数组使用相同的键显示两个结果。这非常令人困惑,但我认为您需要这样:
function ArrayData($id){
foreach($id as $key=>$singleId){
$Data[][$key] = getData($singleId); //here I pass the value as parameter
}
}