Love Fuel?    Donate

FuelPHP Forums

Ask your question about FuelPHP in the appropriate forum, or help others by answering their questions.
Checkbox checks if value exist
  • Hi Guys, I believe that my question is a general PHP logic but I'm at a wits end now and scrathing my head for the last 2 days now. Basically what I want to achieve is to display all the category as a checkbox and tick any of it if its was checked previously. Appreciate if some kind spirit can enlighten the poor soul here ;) http://scrp.at/bua
  • The in_array function expects the second param to be an array not an object... So you have to convert the $business->categories object to an array http://php.net/manual/en/function.in-array.php
  • Thanks Ranie for the reply. I appreciate it. As you said, I have to convert the $business->categories into an array as per below. Thanks for the help. ;) <ul>
    <?php foreach ($categories as $category)
    {
    if (isset($business->categories))
    {
    foreach ($business->categories as $category_value)
    {
    $bcategories[] = $category_value->id;
    }
    }
    else
    {
    $bcategories[] = array();
    }
    ?> <li class="left"><?php echo Form::checkbox('categories[]', $category->id, in_array($category->id, $bcategories) ? true:false).Form::label($category->name,'categories', array('class' => 'inline-label')); ?></li>
    <?php } ?>
    </ul>

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

In this Discussion