I am creating an associative array from XML feed using foreach as you see here:
function load_xml() {
global $db;
if(!$xml=simplexml_load_file($this->path)){
trigger_error('Error reading XML file',E_USER_ERROR);
}
foreach ($xml as $item) {
$xml_items[] = $item_url;
$data[] = ['item_id' => null,
'title' => $item->PRODUCT->__toString(),
'title_draft' => null,
'description' => $item->DESCRIPTION_SHORT->__toString(),
'description_draft' => null,
'text' => $item->DESCRIPTION->__toString(),
'text_draft' => null,
'item_url' => $item->URL->__toString(),
'merchant' => $item->MANUFACTURER->__toString(),
'price' => $item->PRICE_VAT->__toString(),
'price_initial' => $item->PRICE_VAT_SALE->__toString(),
'language_id' => 1,
'subcategory_id' => 0,
'head' => null,
'ean' => null,
'code' => null,
'category_id' => 0,
'subcategory_id' => 0,
'action' => 0,
'rank' => 0,
'keywords' => "",
'published' => 0];
}
return $data;
}
But when I try to use the values in this load_existing_items function I get warning undefined array key:
function load_existing_items(){
global $db;
$data = $this->load_xml();
foreach($data as $key => $value){
$item_url = $data['item_url'];
$merchant = $data['merchant'];
$result = $db->query("SELECT url FROM item WHERE url = '$item_url' AND manufacturer = '$merchant'");
while(($row = mysqli_fetch_assoc($result))) {
$this->$db_items[] = $row['url'];
}
}
}
This is most likely some kind of a really primitive mistake that I made last night while I was desperately finish the code. Thank you for any advice/help.