If value is found in array.

armaclans

Member
I have a custom join field with a tag {$acf_hoursop}. it is checkboxes

This field has:

internal values,

  • mon
  • tue
  • wed
  • thurs
  • fri
  • sat
  • sun


If I want to check if a value exists wouldn't the code be a simple if in array statement?


PHP:
if (in_array('mon', $TMPL['acf_hoursop']))
{
    $TMPL['mon_hoursop'] = '<div class="row custom"><div class="col-md-6 left"><i class="fa fa-clock-o"></i> <b> MONDAY WAS CHECKED</b></div><div class="col-md-6 right"></div></div>';

} else {
   
    $TMPL['mon_hoursop'] = '<div class="row custom"><div class="col-md-6 left"><i class="fa fa-clock-o"></i> <b> MONDAY WAS NOT</b></div><div class="col-md-6 right"></div></div>';

}
Something tells me, that I need to tell the $TMPL to be an array.. Any suggestions?
 

Basti

Administrator
Staff member
Correct, stuff like these are entered into database as a comma seperated string "value 1, value2, value3, etc"

So what you need to do is make an array before out of this value
Code:
// First check if not empty
if (!empty($TMPL['acf_hoursop']))
{
    // This creates an array of the string, we explode the string by delimeter ", " ( notice each item has comma+space between them, so we use that to get the items )
    $hoursop = explode(', ', $TMPL['acf_hoursop']);

    // Do your stuff
    if (in_array('mon', $hoursop))
    {

    }

}
 
Top