Welcome Guest, Not a member yet? Register   Sign In
uri_to_multiassoc()
#1

[eluser]GSV Sleeper Service[/eluser]
this may be useful to someone, very similar to uri_to_assoc(), but allows for multiple values.
stick this is in your libraries/MY_URI.php
Code:
function uri_to_multiassoc($offset) {
    $return_array = array();
    $url_array  = array_slice($this->segment_array(),$offset);        
    for($a=0; $a < count($url_array); $a=$a+2){
        $return_array[$url_array[$a]][] = $url_array[$a+1];
    }        
    return $return_array;
}
example URI
/controller/method/reptiles/gecko/reptiles/salamander/fish/trout/reptiles/monitor_lizard/fish/salmon
example print_r($this->uri->uri_to_multiassoc(2));
Code:
Array
(
    [reptiles] => Array
        (
            [0] => gecko
            [1] => salamander
            [2] => monitor_lizard
        )

    [fish] => Array
        (
            [0] => trout
            [1] => salmon
        )

)




Theme © iAndrew 2016 - Forum software by © MyBB