Smarty Forum Index Smarty
WARNING: All discussion is moving to https://reddit.com/r/smarty, please go there! This forum will be closing soon.

{if $a == $b->c } don't work

 
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    Smarty Forum Index -> Tips and Tricks
View previous topic :: View next topic  
Author Message
stingtao
Smarty Rookie


Joined: 15 Jan 2006
Posts: 5

PostPosted: Sun Jan 15, 2006 4:35 pm    Post subject: {if $a == $b->c } don't work Reply with quote

I don't know why the following wouldn't work. Is it that you can't have two variables in on if-statement or object can't be used?

Code:

{section name=reply_status loop=$joinedstatus}
{if $invitation == $joinedstatus[reply_status]->invitation}
do_something
{/if}
{/section}


Last edited by stingtao on Wed May 05, 2010 10:47 pm; edited 1 time in total
Back to top
View user's profile Send private message
stingtao
Smarty Rookie


Joined: 15 Jan 2006
Posts: 5

PostPosted: Sun Jan 15, 2006 5:03 pm    Post subject: a sample code: please tell me why. Help needed! Reply with quote

Code:

{assign var="temp" value=$joinedstatus[reply_status]->invitation}
<br>joined status => {$temp}
<br>check_secret => {$invitation}
<br>compare =>

{if $temp eq $invitation}
<br>SHOW means "{$temp}" equal "{$invitation}"
{/if}


the above code generate the following result:
Quote:

joined status => ysoyzdhw6f
check_secret => 0
compare =>
SHOW means "ysoyzdhw6f" equal "0"


HELP!!


Last edited by stingtao on Wed May 05, 2010 10:47 pm; edited 1 time in total
Back to top
View user's profile Send private message
boots
Administrator


Joined: 16 Apr 2003
Posts: 5611
Location: Toronto, Canada

PostPosted: Sun Jan 15, 2006 10:00 pm    Post subject: Reply with quote

Actually, that is expected. PHP is loosely typed so when you try to compare a string to an integer, it coerces the string to an int which in this case results in it being equal to 0. What you probaly want is to use the === operator.

see: http://php.net/manual/en/language.types.type-juggling.php
Back to top
View user's profile Send private message
stingtao
Smarty Rookie


Joined: 15 Jan 2006
Posts: 5

PostPosted: Mon Jan 16, 2006 2:43 am    Post subject: Thanks Reply with quote

You are good!
Ya. That's expected as you said.
I modified it and it worked. Thank You!
Back to top
View user's profile Send private message
Display posts from previous:   
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    Smarty Forum Index -> Tips and Tricks All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group
Protected by Anti-Spam ACP