FUDforum
Fast Uncompromising Discussions. FUDforum will get your users talking.

Home » Imported messages » comp.lang.php » Array count for each value in turn syntax?
Show: Today's Messages :: Polls :: Message Navigator
Return to the default flat view Create a new topic Submit Reply
Re: Array count for each value in turn syntax? [message #169969 is a reply to message #169867] Sat, 02 October 2010 10:53 Go to previous messageGo to previous message
August Karlstrom is currently offline  August Karlstrom
Messages: 16
Registered: October 2010
Karma:
Junior Member
On 2010-09-29 02:22, Hamish Campbell wrote:
> isset($totals[$item]) ? $totals[$item] = 1 : $totals[$item]++;

If $totals[$item] has been set you want to increment its value, not set
it to one, so it should be the other way around. The statement is also
better written as

$totals[$item] = isset($totals[$item]) ? $totals[$item] + 1 : 1;

In your version there are side effects inside the conditional expression
and you ignore the result of it which is considered somewhat bad
programming style.


/August

--
The competent programmer is fully aware of the limited size of his own
skull. He therefore approaches his task with full humility, and avoids
clever tricks like the plague. --Edsger Dijkstra
[Message index]
 
Read Message
Read Message
Read Message
Read Message
Read Message
Previous Topic: Iterative interfacing between client and server
Next Topic: Problems modifying date using regex
Goto Forum:
  

-=] Back to Top [=-
[ Syndicate this forum (XML) ] [ RSS ]

Current Time: Sun Nov 24 19:19:21 GMT 2024

Total time taken to generate the page: 0.04302 seconds