Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/261.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 如果else重写值,为什么在我的代码中? 模型 A. 朱姆拉_Php - Fatal编程技术网

Php 如果else重写值,为什么在我的代码中? 模型 A. 朱姆拉

Php 如果else重写值,为什么在我的代码中? 模型 A. 朱姆拉,php,Php,结果应该是这样的 但为什么结果会是这样呢 为什么Column模型中的数据超过10? 如何解决这个问题?=在php中是指给变量赋值,而=用作比较运算符 在代码中,您需要更改此行: <table> <thead> <tr> <th>model</th> <th>a</th> <th>jumlah</th> </tr> </thead> <?p

结果应该是这样的

但为什么结果会是这样呢

为什么Column模型中的数据超过10?
如何解决这个问题?

=
在php中是指给变量赋值,而
=
用作比较运算符

在代码中,您需要更改此行:

<table>
<thead>
<tr>
<th>model</th>
<th>a</th>
<th>jumlah</th>
</tr>

    </thead>
    <?php  foreach((array)$query as $row):
                        if ($row->model='10') {
                            $jumlah=$row->a-10;
                        }else{
                            $jumlah=$row->a-5;
                        };?>
    <td><?php echo $row->model ?></td>
    <td><?php echo $row->a ?></td>
    <td><?php echo $jumlah ?></td>
if ($row->model == '10') {
与:


=
在php中用于为变量赋值,而
=
用作比较运算符

在代码中,您需要更改此行:

<table>
<thead>
<tr>
<th>model</th>
<th>a</th>
<th>jumlah</th>
</tr>

    </thead>
    <?php  foreach((array)$query as $row):
                        if ($row->model='10') {
                            $jumlah=$row->a-10;
                        }else{
                            $jumlah=$row->a-5;
                        };?>
    <td><?php echo $row->model ?></td>
    <td><?php echo $row->a ?></td>
    <td><?php echo $jumlah ?></td>
if ($row->model == '10') {
与:


您使用的是赋值运算符(=),而不是相等运算符(=)。更改此行:

<table>
<thead>
<tr>
<th>model</th>
<th>a</th>
<th>jumlah</th>
</tr>

    </thead>
    <?php  foreach((array)$query as $row):
                        if ($row->model='10') {
                            $jumlah=$row->a-10;
                        }else{
                            $jumlah=$row->a-5;
                        };?>
    <td><?php echo $row->model ?></td>
    <td><?php echo $row->a ?></td>
    <td><?php echo $jumlah ?></td>
if ($row->model == '10') {
为此:

 if ($row->model = '10') {
或者这个:

 if ($row->model == '10') {
在第一种情况下,您告诉编译器存储该值 在变量
$row->model
中输入10

在第二种情况下,我们检查
$row->model
等于字符串值10

在第三种情况下,我们检查
$row->model
等于10的数值


我的猜测是,您可能希望使用第三种情况,除非数字作为文本值存储在数据库中。

您使用的是赋值运算符(=),而不是相等运算符(=)。更改此行:

<table>
<thead>
<tr>
<th>model</th>
<th>a</th>
<th>jumlah</th>
</tr>

    </thead>
    <?php  foreach((array)$query as $row):
                        if ($row->model='10') {
                            $jumlah=$row->a-10;
                        }else{
                            $jumlah=$row->a-5;
                        };?>
    <td><?php echo $row->model ?></td>
    <td><?php echo $row->a ?></td>
    <td><?php echo $jumlah ?></td>
if ($row->model == '10') {
为此:

 if ($row->model = '10') {
或者这个:

 if ($row->model == '10') {
在第一种情况下,您告诉编译器存储该值 在变量
$row->model
中输入10

在第二种情况下,我们检查
$row->model
等于字符串值10

在第三种情况下,我们检查
$row->model
等于10的数值


我猜您可能想使用第三种情况,除非数字作为文本值存储在数据库中。

今天心情不好:

 if ($row->model == 10) {

今天心情不好:

 if ($row->model == 10) {


单个
=
赋值,
=
检查是否相等
=
是一个赋值,您需要
=
比较运算符或不同的语言,但概念完全相同:哈哈,对不起,我忘记了单个
=
赋值,
=
检查是否相等
=/code>是一个赋值,您需要比较运算符或不同的语言,但概念完全相同:哈哈,对不起,我忘记了