12345678910111213141516 |
- <?php
- function category_select_options( $categories, $current=[], $prefix="" ){
- $response = "";
- $current = (array) $current;
- foreach( $categories as $category ){
- $selected = ( in_array( $category->id, $current ) ) ? "selected='selected'" : "";
- $title = $category->title;
- if( $prefix != "" )
- $title = $prefix . " " . $title;
- $response .= "<option value='{$category->id}' {$selected}>{$title}</option>";
- if( $category->has('children') )
- $response .= category_select_options($category->children, $current, $prefix . "-");
- }
- return $response;
- }
|