note 111487 deleted from language.operators.comparison by crell
| From: | crell@php.net | Date: | Thu, 31 Mar 2022 17:46:09 +0000 |
| Subject: | note 111487 deleted from language.operators.comparison by crell | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-217875@lists.php.net to get a copy of this message | ||
Note Submitter: bimal at sanjaal dot com
----
I came across peculiar outputs while I was attempting to debug a script
<?php
# Setup platform (pre conditions somewhere in a loop)
$index=1;
$tally = array();
# May work with warnings that $tally[$index] is not initialized
# Notice: Undefined offset: 1 in D:\htdocs\colors\ColorCompare\i.php on line #__
# It is an old fashioned way.
# $tally[$index] = $tally[$index] + 1;
# Does not work: Loops to attempt to change $index and values are aways unaffected
$tally[$index] = isset($tally[$index])?$tally[$index]:0+1;
$tally[$index] = isset($tally[$index])?$tally[$index]:0+1;
$tally[$index] = isset($tally[$index])?$tally[$index]:0+1;
/*
# These three lines output:
Array
(
[1] => 1
)
*/
# Works: This is what I need/expect
# $tally[$index] = 1+(isset($tally[$index])?$tally[$index]:0);
print_r($tally);
?>
The second block obviously does not work what one expects.
Third part is good.