$line[1] = intval($line[1]); //这个这样写是什么意思?

WBOY
发布: 2016-06-23 14:38:33
原创
1579 人浏览过

<?php  //create short variable name  $DOCUMENT_ROOT = $_SERVER['DOCUMENT_ROOT'];?><html><head>  <title>Bob's Auto Parts - Customer Orders</title></head><body><h1>Bob's Auto Parts</h1><h2>Customer Orders</h2><?php  //Read in the entire file.  //Each order becomes an element in the array  $orders= file("$DOCUMENT_ROOT/../orders/orders.txt");  // count the number of orders in the array  $number_of_orders = count($orders);  if ($number_of_orders == 0) {    echo "<p><strong>No orders pending.          Please try again later.</strong></p>";  }  echo "<table border=\"1\">\n";  echo "<tr><th bgcolor=\"#CCCCFF\">Order Date</th>            <th bgcolor=\"#CCCCFF\">Tires</th>            <th bgcolor=\"#CCCCFF\">Oil</th>            <th bgcolor=\"#CCCCFF\">Spark Plugs</th>            <th bgcolor=\"#CCCCFF\">Total</th>            <th bgcolor=\"#CCCCFF\">Address</th>         <tr>";  for ($i=0; $i<$number_of_orders; $i++) {    //split up each line    $line = explode("\t", $orders[$i]);    // keep only the number of items ordered    $line[1] = intval($line[1]);     $line[2] = intval($line[2]);    $line[3] = intval($line[3]);    // output each order    echo "<tr>             <td>".$line[0]."</td>             <td align=\"right\">".$line[1]."</td>             <td align=\"right\">".$line[2]."</td>             <td align=\"right\">".$line[3]."</td>             <td align=\"right\">".$line[4]."</td>             <td>".$line[5]."</td>          </tr>";  }  echo "</table>";?></body></html>
登录后复制


$line[1] = intval($line[1]); //这个这样写是什么意思? intval手册是这样描述intval通过使用特定的进制转换(默认是十进制),返回变量 var 的 integer 数值。但是将这个integer数值赋给$line[1]起到什么作用?


回复讨论(解决方案)

intval() 变量转成整数类型$line[1] = intval($line[1]); $line[2] = intval($line[2]);$line[3] = intval($line[3]);转化成整数类型的变量重新组合数组$line你也可以这样,重新赋值给变量$line_a = intval($line[1]); $line_b = intval($line[2]);$line_c = intval($line[3]);那么你的模板显示,对应的需要变动。
登录后复制

$line[1] = intval($line[1]); 
的作用是:确保最终的 $line[1] 的值是整数

何况原作者已经做了说明
38行有 keep only the number of items ordered

来源:php.cn
本站声明
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn
热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板
关于我们 免责声明 Sitemap
PHP中文网:公益在线PHP培训,帮助PHP学习者快速成长!