041_TF_Parsing-TF-ValuesHow do you process values in Titan Framework? How are they stored?

First, let’s count the types of values in existence, then how they are processed:

1. The Boolean

It gives the True or False value, and all undefined values are False by default. Checkboxes for example are boolean in nature.

To process Boolean:

Simply evaluating the value, $titan->getOption(‘my_option’) or ! $titan->getOption(‘my_option’) will do. Similarly, true and false equality comparisons also work. Note that they’re bitwise boolean and not string value ‘true’ and ‘false’.

if ($titan->getOption(‘my_option’)) {

$this->do();

}

if ($titan->getOption(‘my_option’) === true) {

$this->also();

}

if ($titan->getOption(‘my_option’) === true) {

$this->also();

}

if (!$titan->getOption(‘my_option’)) {

$this->do();

}

if ($titan->getOption(‘my_option’) === false) {

$this->also();

}

2. String

Text values, some numbers, and mixed numbers and alphabets comprises strings. Values carrying multiple values in comma-separated values also fall under string. Textboxes are commonly string values.

To process strings:

$output = $titan->getOption(‘my_option’);

$option = ctype_alnum($output) – Checks if $output is alphanumeric in value. This means symbols will cause it to return false.

$option = ctype_alpha($output) – Checks if $output is only alphabet letters in value. This means numbers and symbols will cause it to return false.

$option = ctype_alnum($output) – Checks if $output is alphanumeric in value. This means symbols will cause it to return false.

$option = ctype_digit($output) – Checks if $output is numbers in value. This means alphabets and symbols will cause it to return false.

$option = is_numeric($output) – Checks if $output is a numerical value. This includes float (with decimal points) or hexadecimal values. Anything else returns false.

$option = is_float($output) – Checks if $output is a float value, meaning numbers with decimal points. This means alphabets, symbols and integers will cause it to return false.

3. Array

For option sets that allow multiple selections, they are returned as array. Each array key value may be any of the first two types. Multicheck and Select (when configured to do so) are examples of options that gives array values as output.

Integers are purely number values, and are not used. String values take up integer role. The same is true for float values.

In PHP, there’s validation of values to ensure that the output you’re getting is the one that’s stored.

To process array values:

If you need the array values in a continuous string, good old implode() will do. Otherwise, you can run a foreach() or if you need some advanced parsing, each() and while() to get to the values. Foreach does the job and unless the aforementioned case applies to you, you don’t need to look elsewhere for array parsing.

$output = $titan->getOption(‘my_option’);

$option = implode(‘,’, $output);

foreach ($output as $key => $value) {
echo $value;
}

Note that options with array values will still return as array even if you only selected one value. Use empty() to check if the array is populated, meaning if the user made a selection in the multicheck or select or other array-based options.

Leave a Reply