Code:
<?
error_reporting(E_ALL);
$orig = $_POST['size'];
//$orig = array(30,31,32,34,35,37,38,39,41,42,43,44,45); //list of entries user has entered - example
$cmp = array(30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46);
$new = array();
//$cnew = array(30,31,32,0,34,35,0,37,38,39,0,41,42,43,44,45,0); - how it should look when its outputted
$count = count($orig);
if($count == 17) {
//do insert because 17 records exist and thats how many we should have
} else {
//got to edit array
for($i = 0; $i < 17; $i++) {
if($cmp[$i] == $orig[$i]) {
array_push($new, $cmp[$i]);
} else {
for($x = $i; $x < 17; $x++) {
if(count($new) == $x) {
$remain = 17 - $x;
for($x = 0; $x < $remain; $x++) {
array_push($new, "0");
}
} else {
echo $i.' ';
echo $orig[$x].' '.$cmp[$i].'<br>';
if($orig[$i] == $cmp[$x]) {
array_push($new, $cmp[$x]);
$i++;
} else {
array_push($new, "0");
}
}
}
}
}
}
//INSERT INTO sql goes here
/*echo '<br>';
foreach($new as $value) {
echo $value.',';
}
echo '<br>';
foreach($cnew as $value) {
echo $value.',';
}*/
?>
Right so basically what it does is checks each array position and compared to a standard 1, if its not right then it will add a zero until it finds the right 1.
Bookmarks