I wrote this function a couple of months ago for a Webtech course at
my university. But I was wondering if anyone has anyother idea to ease
this with more intregreated functions.

Any way.. the problem is that in my code I often write this peace of
code:
$variable = isset($anothervariable)?$anothervariable:"<defaultvalue>";

Which in it self isnt a ploblem, but if you have a huge array, that
expression will be realy big, and easy to make misstakes when
copypasting.

My function and usage:
$variable = get($array, "Firstdim.secondim.thirddim.soon",
"defaultvalue",
"optional_boolean_if_you_want_another_value_on_isset");

        function get(&$arr, $keystr, $default = "", $ifset = null) {
                $keys = preg_split("/\./", $keystr);
                $c =& $arr;
                foreach($keys as $k) {
                        if(isset($c[$k]) && !is_string($c))
                                $c =& $c[$k];
                        else {
                                return $default;
                        }
                }
                if(!isset($ifset))
                        return $c;
                else
                        return $ifset;
        }

Feedback! plz :P
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Cake 
PHP" group.
To post to this group, send email to cake-php@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to