Completed
Push — master ( 0aabb4...282eac )
by Faysal
01:10
created

helpers.php ➔ prepare_options()   B

Complexity

Conditions 7
Paths 12

Size

Total Lines 28

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 7
nc 12
nop 2
dl 0
loc 28
rs 8.5386
c 0
b 0
f 0
1
<?php
2
3
if (! function_exists('prepare_attributes')) {
4
5
    function prepare_attributes(array $attributes)
6
    {
7
        $attributes_string = '';
8
        
9
        foreach($attributes as $key => $value){
10
            $attributes_string .= $key . '="' . $value . '" ';
11
        }
12
13
        return $attributes_string;
14
    }
15
}
16
17
18
if (! function_exists('prepare_options')) {
19
20
    function prepare_options($data, $selected)
21
    {
22
        if($data instanceof Illuminate\Support\Collection){
23
            $data = $data->toArray();
24
        }
25
        $options_html = '';
26
        
27
        if(array_values($data) !== $data){
28
            foreach($data as $key => $value){
29
                if($key == $selected){
30
                    $options_html .= '<option selected="selected" value="'. $key .'">'. $value.'</option>';
31
                }else{
32
                    $options_html .= '<option value="'. $key .'">'. $value.'</option>';
33
                }
34
            }
35
        }else{
36
            foreach($data as $key){
37
                if($key == $selected){
38
                    $options_html .= '<option selected="selected" value="'. $key .'">'. $key.'</option>';
39
                }else{
40
                    $options_html .= '<option value="'. $key .'">'. $key.'</option>';
41
                }
42
            }
43
        }
44
        
45
46
        return $options_html;
47
    }
48
}