CodeIgniter Forums
Array function - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23)
+--- Thread: Array function (/showthread.php?tid=28533)



Array function - El Forum - 03-14-2010

[eluser]frist44[/eluser]
I know this is a stupid question, but is there a way to perform a function like "urlencode" to every value in an associative array easily?

Right now, I'm doing the code below, and it works, I just figured there's a more elegant way to do this.

Code:
foreach ($arr_uri as $key => $value) {
            $fixed[$key] = urlencode($value);
        }



Array function - El Forum - 03-14-2010

[eluser]jáquer[/eluser]
array_map()

Code:
$arr_uri = array_map('urlencode', $arr_uri);



Array function - El Forum - 03-14-2010

[eluser]frist44[/eluser]
Thanks!