Reputation: 607
I eliminated another question where I explained everything wrong, I hope this is more specific
I saw similar questions but this case is something particular
I need that for each value of the array that I give, return the result with its respective key ([264], [265], etc).
i have this array:
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
}
my function:
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;
}
result of my function:
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"
}
}
}
}
the array shows both results with the same key
Upvotes: 0
Views: 30
Reputation: 99533
It's pretty confusing, but I think you want this:
function ArrayData($id){
foreach($id as $key=>$singleId){
$Data[][$key] = getData($singleId); //here I pass the value as parameter
}
}
Upvotes: 1