ul()

ul($list[, $attributes = ''])

Parameters:
  • $list (array) – List entries
  • $attributes (array) – HTML attributes
Returns:

HTML-formatted unordered list

Return type:

string

Permits you to generate unordered HTML lists from simple or multi-dimensional arrays. Example:

1
2
3
4
5
6
7
8
9
10
11
12
13
$list = array(
        'red',
        'blue',
        'green',
        'yellow'
);
 
$attributes = array(
        'class' => 'boldlist',
        'id'    => 'mylist'
);
 
echo ul($list, $attributes);

The above code will produce this:

1
2
3
4
5
6
<ul class="boldlist" id="mylist">
        <li>red</li>
        <li>blue</li>
        <li>green</li>
        <li>yellow</li>
</ul>

Here is a more complex example, using a multi-dimensional array:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
$attributes = array(
        'class' => 'boldlist',
        'id'    => 'mylist'
);
 
$list = array(
        'colors'  => array(
                'red',
                'blue',
                'green'
        ),
        'shapes'  => array(
                'round',
                'square',
                'circles' => array(
                        'ellipse',
                        'oval',
                        'sphere'
                )
        ),
        'moods'  => array(
                'happy',
                'upset' => array(
                        'defeated' => array(
                                'dejected',
                                'disheartened',
                                'depressed'
                        ),
                        'annoyed',
                        'cross',
                        'angry'
                )
        )
);
 
echo ul($list, $attributes);

The above code will produce this:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
<ul class="boldlist" id="mylist">
        <li>colors
                <ul>
                        <li>red</li>
                        <li>blue</li>
                        <li>green</li>
                </ul>
        </li>
        <li>shapes
                <ul>
                        <li>round</li>
                        <li>suare</li>
                        <li>circles
                                <ul>
                                        <li>elipse</li>
                                        <li>oval</li>
                                        <li>sphere</li>
                                </ul>
                        </li>
                </ul>
        </li>
        <li>moods
                <ul>
                        <li>happy</li>
                        <li>upset
                                <ul>
                                        <li>defeated
                                                <ul>
                                                        <li>dejected</li>
                                                        <li>disheartened</li>
                                                        <li>depressed</li>
                                                </ul>
                                        </li>
                                        <li>annoyed</li>
                                        <li>cross</li>
                                        <li>angry</li>
                                </ul>
                        </li>
                </ul>
        </li>
</ul>
doc_CodeIgniter
2025-01-10 15:47:30
Comments
Leave a Comment

Please login to continue.