开发者

How to display the previously assigned value in a variable in PHP?

开发者 https://www.devze.com 2023-02-19 10:24 出处:网络
I have some PHP statements as <?php $i = 10; $i = 15; ec开发者_如何学Pythonho $i; ?> Now we all are aware of the fact that this will give us \"15\", what should i do after assignment to the

I have some PHP statements as

<?php 
$i = 10;
$i = 15;
ec开发者_如何学Pythonho $i;
?>

Now we all are aware of the fact that this will give us "15", what should i do after assignment to the variable $i with value "15", so that we can get output as "10"?


This isn't specific to PHP. When ever you have a list of statements like that that assign values to a variable, the variable will have the value set by the last statement to execute.


You can't. Once a variable has been reassigned its previous value is lost.


You cannot achieve that. But you might do this.

$i[] = 10;
$i[] = 15;

If you assign as above, you will get the following:-

echo $i[0]  // will give 10
echo $i[1]  // will give 15


you can use array otherwise no way.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号