jeudi 25 août 2016

Extract value from array then run if on value

I have an array of items (cheese) in a checkbox format like so

array(
    'type' => 'checkbox',
    "holder" => "div",
    "class" => "",
    "heading" => __("Choose your cheese topping", 'rbm_menu_item'),
    'param_name' => 'cheesbox',
    'value' => array( 'Cheddar'=>'Chedder', 'Gouda'=>' Gouda', 'Bleu'=>' Bleu'),
    "description" => __("<br /><hr class='gduo'>", 'rbm_menu_item')
    ),

The values of the array are displayed on a page (in a hidden div) using the heredoc declaration with an if to check if the checkbox has been used - if the return is empty the div does not show - if one of the checkboxes is "checked" then it does.

///Cheese selections
if (!empty($cheesbox)) {
      $output .= <<< OUTPUT
        <br />
        <div class="sides">Comes with: <p>{$cheesebox}</p></div>
        <br />
OUTPUT4;
}

What I need to do is pull any one of the values in the array and if its in the $cheesebox the do something.

Ive tried using an ifelse like this

if ( ('$cheesebox') == "Cheddar" ){
           echo "Your topping is Cheddar";
        }
            elseif ( ('$cheesebox') == "Gouda" ){
        {
           echo "Your topping is Gouda";
        }
            elseif ( ('$cheesebox') == "Bleu" ){
        {
           echo "Your topping is Bleu";
        } 

however this does not work - I'm sure I have it wrong somehere along the line or does the heredoc function only allow for one?

if so is there a way to accomplish this?

Aucun commentaire:

Enregistrer un commentaire