Help witn an array

3 posts by 2 authors in: Forums > CMS Builder
Last Post: March 24, 2014   (RSS)

By nmsinc - March 13, 2014

I have data located in a field text box as follows:

True

False

Correct

Incorrect

Maybe True

Maybe False

Within the CMS, I need to grab this data in an array and compare it to another field. If this field matches with any of the data in that array then the text listed in a dropdown output would be colored blue, else it would colored black.

Any help would be appreciated – Thanks nmsinc

nmsinc

By Daryl - March 24, 2014

Hi nmsinc,

You can get the value of the text box as an array by exploding it and use in_array() function to check it against another field. For example:

$textBoxValuesAsArray = explode("\n", strip_tags($testRecord['text_box_field']));

$textColor = '';
if (in_array($testRecord['another_field'], textBoxValuesAsArray)){
   //set the text color to blue
   $textColor = "#0000FF";
}
else{
   //set the text color to black
   $textColor = "#000000";
}

Hope this helps!

Cheers,

Daryl Maximo
PHP Programmer - interactivetools.com