I'm trying to compare to XML files. I have pulled the new.xml apart and put all the barcodes into an array. I am then trying to loop through the old.xml file and testing if the barcode exists in the array. If the barcode does exist then I want to echo a table row. When I get that working I will flip it to print if it ! exist. The XML files are structured like this:
<Products>
<Product>
<Id>2209</Id>
<Barcode>4890888123702</Barcode>
</Product>
</products>
My HTML and PHP looks like this:
<html>
<head>
<title>Feeds = $$$$</title>
<!-- Latest compiled and minified CSS -->
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css">
<!-- Optional theme -->
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap-theme.min.css">
<!-- Latest compiled and minified JavaScript -->
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/js/bootstrap.min.js"></script>
</head>
<body>
<div class="container-fluid">
<?php
//Get the old XML file
if (file_exists('old.xml')) {
$oldxml = simplexml_load_file('old.xml');
//Load all the old product IDs into an array
$oldproducts = array();
foreach($oldxml->Product as $oldproduct){
$oldproducts[] = $oldproduct->Id;
}
}else{
echo "Old XML does not exist";
}
//Get the new xml file
if (file_exists('new.xml')){
$newxml = simplexml_load_file('new.xml');
//Load all the new product IDs into an array
$newproducts = array();
foreach ($newxml->Product as $newproduct){
$newproducts[] = $newproduct->Id;
}
}else{
echo "New XML file does not exist";
}
?>
<div class="table-responsive">
<table class="table table-striped">
<?php
foreach($oldxml->Product as $oldproduct) {
$x = $oldproduct->Id;
if(in_array($x, $newproducts)){
echo '<tr>';
echo '<td>' . $x . ' has been taken out of stock' . '</td>';
echo '</tr>';
}
}
?>
</table>
</div>
</div>
</body>
</html>
The loop doesn't return anything. If I use a hard coded barcode instead of the $x, it will find it and work properly.