I need to avoid eval() again. I want to access a multidimensional array like this:
$items = $xml2array[$explode_path[0]][$explode_path[1]];
The thing is that $explode_path[0] and $explode_path[1] are calculated through a for loop:
for($i=0; $i<$count_explode; $i++) { }
Right now the entire code looks like this:
function getValues($contents, $xml_path) {
$explode_path = explode('->', $xml_path);
$count_explode = count($explode_path);
$xml2array = xml2array($contents);
$correct_string = '$items = $xml2array';
for($i=0; $i<$count_explode; $i++) {
$correct_string .= '[$explode_path['.$i.']]';
}
$correct_string .= ';';
eval($correct_string);
return $items;
}
$contents = readfile_chunked($feed_url, true);
$items = getValues($contents, 'deals->deal'); # will get deals->deal from MySQL
foreach($items as $item) {
echo $item['deal_title']['value'].' - '.$item['dealsite']['value'].'<br />';
}
I can't figure out how I can access the $xml2array array that way:
$items = $xml2array[$explode_path[0]][$explode_path[1]];
Any help would be highly appreciated!