This is my input array:
INPUT :
$input["a"]["b"]["UK"] = 96 ;
$input["a"]["c"]["UK"] = 69 ;
$input["a"]["bp"]["USA"] = 29 ;
$input["a"]["c"]["USA"] = 59 ;
$input["a"]["dd"]["UK"] = 31 ;
$input["a"]["cg"]["UK"] = 38 ;
I want to get a new array that will contain only ["USA"]. So output have to be..............
OUTPUT :
$output["a"]["bp"]["USA"] = 29 ;
$output["a"]["c"]["USA"] = 59 ;
IS IT POSSIBLE ?
This will work.
$input["a"]["b"]["UK"] = 96 ;
$input["a"]["c"]["UK"] = 69 ;
$input["a"]["bp"]["USA"] = 29 ;
$input["a"]["c"]["USA"] = 59 ;
$input["a"]["dd"]["UK"] = 31 ;
$input["a"]["cg"]["UK"] = 38 ;
$tempResult = array();
foreach($input as $key => $value){
foreach($value as $subkey => $subvalue){
foreach($subvalue as $finalkey => $finalvalue){
if($finalkey == 'USA') {
$tempResult[$key][$subkey][$finalkey] = $finalvalue;
}
}
}
}
echo '<pre>';print_r($tempResult);echo '</pre>';
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With