Skip to content

Instantly share code, notes, and snippets.

@erkattak
Created June 21, 2011 18:46
Show Gist options
  • Save erkattak/1038562 to your computer and use it in GitHub Desktop.
Save erkattak/1038562 to your computer and use it in GitHub Desktop.
function checkbox_list ($data, $name = 'list', $parent = 0, &$label = null) {
if (!empty($data)) {
echo '<div class="categories sub">';
foreach ($data as $item) {
if (isset($item['children']) && !empty($item['children'])){
$label .= (isset($label)) ? ' ' . $item['name'].' &raquo;' : $item['name'].' &raquo;';
checkbox_list($item['children'], $name, $item['id'],$label);
}else{
echo (isset($label)) ? '<h3>'.$label.'</h3>' : false;
echo '<label for="'.$name.'_'.$item['id'].'"><input type="checkbox" name="'.$name.'[]" value="'.$item['id'].'" id="'.$name.'_'.$item['id'].'" />'.$item['name'].'</label>';
unset($label);
}
}
echo '</div>';
}
}
checkbox_list($classifications);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment