分解字符串并添加一个数字?php
我真的受够了。我的问题如下: 代码:分解字符串并添加一个数字?php,php,explode,Php,Explode,我真的受够了。我的问题如下: 代码: 我只想在$string中的数字上添加一些内容。因此,它应该响应2。然而,它与1相呼应 怎么了?使用预增量: $final = "secound value is: ".++$highest; 更多信息:使用预增量: $final = "secound value is: ".++$highest; 更多信息:请尝试以下代码 <?php $highest = 0; $string = "a.1"; $array = explode(".",$s
我只想在$string中的数字上添加一些内容。因此,它应该响应2。然而,它与1相呼应
怎么了?使用预增量:
$final = "secound value is: ".++$highest;
更多信息:使用预增量:
$final = "secound value is: ".++$highest;
更多信息:请尝试以下代码
<?php
$highest = 0;
$string = "a.1";
$array = explode(".",$string);
$highest = $array[1];
$final = "secound value is: ". ++$highest;
echo $final;
?>
原因是,$highest++
是后期增量。它只有在使用后才会增加值。而+$highest
是pre increment,将首先递增该值,然后使用它尝试下面的代码
<?php
$highest = 0;
$string = "a.1";
$array = explode(".",$string);
$highest = $array[1];
$final = "secound value is: ". ++$highest;
echo $final;
?>
原因是,
$highest++
是后期增量。它只有在使用后才会增加值。并且,+$highest
是预增量,将首先增加值,然后使用它您正在进行后增量。如果你做一个预增量,你会得到2作为你的结果。这是你想要的吗
$final = "secound value is: ".++$highest;
您正在进行后期增量。如果你做一个预增量,你会得到2作为你的结果。这是你想要的吗
$final = "secound value is: ".++$highest;
只是想把答案从盒子里拿出来。您可以保存自己的爆炸和阵列,您可能不需要/不想要
$highest = substr($str, 2) + 1;
只是想把答案从盒子里拿出来。您可以保存自己的爆炸和阵列,您可能不需要/不想要
$highest = substr($str, 2) + 1;
增量前和增量后之间存在差异
pre-increment-(++$highest)
At first increase the value by one then executes the statement.
post-increment-($highest++)
At first executes the statement then increase the value by one.
所以在这种情况下,您必须使用pre-increment。然后,将在值的增量之后执行该行
请尝试以下代码:
<?php
$highest = 0;
$string = "a.1";
$array = explode(".",$string);
$highest = $array[1];
$final = "secound value is: ".++$highest;
echo $final;
?>
增量前和增量后存在差异
pre-increment-(++$highest)
At first increase the value by one then executes the statement.
post-increment-($highest++)
At first executes the statement then increase the value by one.
所以在这种情况下,您必须使用pre-increment。然后,将在值的增量之后执行该行
请尝试以下代码:
<?php
$highest = 0;
$string = "a.1";
$array = explode(".",$string);
$highest = $array[1];
$final = "secound value is: ".++$highest;
echo $final;
?>
,因为它在分配给变量后会递增。将post$highest++
increment更改为++$highest
,因为将其分配给变量后,它会递增。将post$highest++
增量更改为++$highest
有什么区别?我从来不知道有这样的事。就这样。谢谢大家!@约翰顿,原因在我的回答中有什么不同?我从来不知道有这样的事。就这样。谢谢大家!@Johrdon,原因就在我的回答中我试着使用这个,但结果是$highest1,加法操作创建了一个串联而不是加法。@LuigiLopez我只是仔细检查了$string=“a.1”$最高=子字符串($string,2)+1;echo美元最高代码>和回声2
out。在php中,+
不能用于字符串连接,只能用于
。我尝试使用它,但结果是$highest1,添加操作创建一个连接,而不是添加。@LuigiLopez我只是双击了$string=“a.1”$最高=子字符串($string,2)+1;echo美元最高代码>和回声2
out。在php中,+
不能用于字符串连接,只能用于
。