Forums / Developer / Comparison loop returns true twice without altering values

Comparison loop returns true twice without altering values

Author Message

Eirik Alfstad Johansen

Monday 21 February 2005 11:02:25 am

Hi,

Could someone please explain to me why the following code:

{let options=hash('all', 'All weekdays', 1, 'Monday', 2, 'Tuesday', 3, 'Wednesday', 4, 'Thursday', 5, 'Friday', 6, 'Saturday', 0, 'Sunday')}
	{let selected_option='all'}
	        {section name=Child loop=$options}
			{$:key}: {eq($:key, $selected_option)}<br />
		{/section}
	{/let}
{/let}

...returns the following output:

 all: 1
1:
2:
3:
4:
5:
6:
0: 1

As you might guess, I was expecting only the first iteration to evaluate to true.

Thanks in advance !

Sincerely,

Eirik Alfstad Johansen
http://www.netmaking.no/

Kristian Hole

Wednesday 23 February 2005 6:04:51 am

Kristian

http://ez.no/ez_publish/documenta...tricks/show_which_templates_are_used
http://ez.no/doc/ez_publish/techn...te_operators/miscellaneous/attribute

Eirik Alfstad Johansen

Wednesday 23 February 2005 7:11:48 am

Hi Kristian,

Thanks for confirming. I've posted the bug here: http://ez.no/bugs/view/6250

Sincerely,

Eirik Alfstad Johansen
http://www.netmaking.no/

Kristian Hole

Wednesday 23 February 2005 8:15:51 am

Hi again!

I've closed the bug. The reason for the bug:

This is because of the way PHP works, and the way it converts strings to integers and visa versa. The resolution is to not to compare integers to strings (or to not to compare strings with the number 0).

A resolution to your problem is either to use 7 or -1 as sunday, or use a number for "any".

Kristian

http://ez.no/ez_publish/documenta...tricks/show_which_templates_are_used
http://ez.no/doc/ez_publish/techn...te_operators/miscellaneous/attribute