Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to check if a boolean variable is 1/true or 0/false with TinyButStrong?

I'm kinda new with TinyButStrong, and I would like to know how I can check if a boolean variable is 0 or 1 ? For example, I have this:

$TBS->MergeBlock('tests', $tests);

And $tests have a variable call 'activated' which is a boolean. So, in my .docx document, I would like to write the string 'Activated' if the variable is set to true(1), and 'non-activated' if it set to false(0).

Which syntax should I use in the .docx document ?

Thanks in advance.

like image 621
NH3 Avatar asked Dec 20 '12 09:12

NH3


People also ask

How do you check if a boolean is true or false?

An alternative approach is to use the logical OR (||) operator. To check if a value is of boolean type, check if the value is equal to false or equal to true , e.g. if (variable === true || variable === false) . Boolean values can only be true and false , so if either condition is met, the value has a type of boolean.

How can check boolean value in if condition in PHP?

The is_bool() function checks whether a variable is a boolean or not. This function returns true (1) if the variable is a boolean, otherwise it returns false/nothing.

How do you know if one variable is true?

It's the simplest and fastest way to do this. If you want to check that a variable is explicitly True or False (and is not truthy/falsy), use is ( if variable is True ). If you want to check if a variable is equal to 0 or if a list is empty, use if variable == 0 or if variable == [] .

Is 1 true in PHP?

The boolean values are called true and false in php. In the case of true , the output is 1 . While with the false , it does not show any output. It is worth noting that the browser always renders these values in strings.


1 Answers

They are several ways to format values during the merging, but by default TBS converts data items into strings using the PHP implicit conversion.

Thus, true is converted into '1' and false is converted into '' (empty string).

For the non-existing value: If the key in the array you want to merge does not exist, then you can avoid the TBS error message using parameter noerr, and the value for replacement is '' (empty string).

So your solution is :

[test.ativated;noerr;if [val]=1;then 'Activated';else 'non-activated']
like image 85
Skrol29 Avatar answered Sep 28 '22 18:09

Skrol29