donglingsai2880 2013-07-13 12:54
浏览 26
已采纳

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

  • 写回答

2条回答 默认 最新

  • duanqiao8925 2013-07-13 13:39
    关注

    Do this:

    foreach($missingvalue as $key => $value)
    {
        printf('WARNING: The invoice '.$value.' is missing.');
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥35 MIMO天线稀疏阵列排布问题
  • ¥60 用visual studio编写程序,利用间接平差求解水准网
  • ¥15 Llama如何调用shell或者Python
  • ¥20 谁能帮我挨个解读这个php语言编的代码什么意思?
  • ¥15 win10权限管理,限制普通用户使用删除功能
  • ¥15 minnio内存占用过大,内存没被回收(Windows环境)
  • ¥65 抖音咸鱼付款链接转码支付宝
  • ¥15 ubuntu22.04上安装ursim-3.15.8.106339遇到的问题
  • ¥15 blast算法(相关搜索:数据库)
  • ¥15 请问有人会紧聚焦相关的matlab知识嘛?