PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Wednesday, June 29, 2022

[FIXED] How to assign an expression to a variable and check if it is odd or even in Smarty Script

 June 29, 2022     php, smarty     No comments   

Issue

In smarty script I need to assign a random integer to a variable and display some content if that variable is odd or even. I know I can get a random integer with

{math equation = rand(1,20)}

But how to assign it to a variable and check if it is odd or even?


Solution

To assign to a variable in Smarty you can use

{$check=rand(1,20) nocache}

https://www.smarty.net/docs/en/language.builtin.functions.tpl#language.function.shortform.assign

To check if a variable is even you can use

{if $check is even}
   ...
{/if}

https://www.smarty.net/docs/en/language.function.if.tpl



Answered By - brombeer
Answer Checked By - Cary Denson (PHPFixing Admin)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing