I am trying to go through multidimensional array, I have an array of keys that I want to find in the multidimensional array, and after i found it, assaign its value to said key. For example I have an key Keyword
and I have an array
Array (
[root] => Array (
[row] => Array (
[0] => Array (
[Status] => Enabled
[Keyword] => Toaletna voda
[Campaign] => Lešenari
[Adgroup] => Lešenaris
[BidStrategyType] => InheritFromParent
[Bid] => 0.05
[Matchtype] => Broad
[Clicks] => 0
[Impr.] => 0
[Conv.] => 0
)
)
)
)
Well I tried to do it recursively, foreach($array as $key => $value)
if $value is an array, then i need to go another level inside. I managed to get the values assigned to keys that i wanted, but instead of 12 items I got 100 of them.
Array of cloumn names
$bing = array(
"Adgroup",
"Campaign",
"Keyword",
"Clicks",
"Impr.",
"Conv.",
"Bid",
"Adgroup"
);
Working function for CSV format
public function LoadCsvReport($adSystemColumnsColumns = array())
{
require "config.php";
$key = array();
$flag = false;
$csvfile = fopen(dirname(__FILE__) . "/result.csv", "r");
while ($file = fgetcsv($csvfile)) {
if (!$flag) {
/*Loop through config array which contains names of columns of our interest
If row from file contains name from config, then that name will have assigned
index of that column
*/
foreach ($bing as $name)
if ($value = array_search($name, $file)) {
$key[$name] = $value;
$flag = true;
}
//After column indexes are assigned to names skip current row
if ($flag)
continue;
}
if ($flag) {
foreach ($key as $columnName => $index) {
/*Get columnname and index, items from $file[$index] are assign to
corresponding array with columnName as index
*/
if ($file[$index] === "-")
break;
$this->report[$columnName][] = $file[$index];
//$key[$index] = array($item => $file[$item]);
}
}
}
fclose($csvfile);
return $this->report;
}