php如何循环数组的值

i have the following php code:

$range=range(1,$count);
$value=implode(",",$range);
$query1="SELECT DISTINCT numar_factura FROM creeazafactura WHERE numar_factura IN ($value)";
$result1=mysql_query($query1);

while ($rowx = mysql_fetch_assoc($result1)) {
    $getvalue[]=$rowx['numar_factura'];
}
$missingvalue = array_diff($range,$getvalue);

print_r($range);
print_r($getvalue);
print_r($missingvalue);

with the output:

Array
(
    [0] => 1
    [1] => 2
    [2] => 3
)

Array
(
    [0] => 1
    [1] => 2
)

Array
(
    [2] => 3
)

what i'm trying to figure out is, how to do so that the following line

printf("WARNING: The invoice $missing[2] is missing.");

will work always. Why i'm telling always? Because now id deleted the 3rd invoice, but if i delete the second invoice i will have array[1] to output in $missing

The answer is to make a loop so that i will have in the printf the $missing[$loop],

where the loop is searching for one or two invoices deleted.. and output 1 or two lines.

Easy to say, hard to do, when you are a beginner and you want to do an easy invoice system for a friend who uses excel :)

If you could provide some examples, or some links to some documentation, you could do me a great favor. Thank you

Do this:

foreach($missingvalue as $key => $value)
{
    printf('WARNING: The invoice '.$value.' is missing.');
}

So aim is to get the ID of a missing invoice. Try this:

// here's your missing invoice array
$missingvalue = array_diff($range,$getvalue);
// get keys of it
$missingvalue_keys = array_keys($missingvalue);
// and now get the value from $missingvalue by key from $missingvalue_keys
printf('WARNING: The invoice ' . $missing[$missingvalue_keys[0]] . ' is missing.');

// if you have multiple values in $missingvalue than you dont need keys
foreach ($missingvalue as $value)
    printf('WARNING: The invoice ' . $value . ' is missing.');
// or with implode
printf('WARNING: The invoices ' . implode(',', $missingvalue) 
        . ' are missing.');