Yes, I wanted to change mine to a variable number of arguments, however call-time passing by reference is now deprecated, and I rarely need to use more than 2 arguments.
Cheers, Adam On Apr 17, 1:05 am, "[EMAIL PROTECTED]" <[EMAIL PROTECTED]> wrote: > That looks a lot like something I cooked up. > It can take any number of args and the first one that is not "empty" > is returned. Usually I only use two args but occasionally I need > another. > > function mor() > { > $args = func_get_args(); > foreach ( $args as $arg ) > { > if ( !empty($arg) ) { return $arg; } > } > return false; > > } > > USAGE: $str = mor($notset,false,'','hello'); > But to be rid of variable varnings in my function I have to put the > ampersand in the function call: > USAGE: $str = mor(&$notset,false,'','hello'); > > just in case anyone else finds it useful > /Martin > > On Apr 16, 12:53 pm, Adam Royle <[EMAIL PROTECTED]> wrote: > > > I've used something like this in the past which I keep in my > > bootstrap, however I've started moving away from using this so my code > > is more readable. It is very handy though when you need to access lots > > of variables that might not exist. > > >https://trac.cakephp.org/ticket/2774 > > > $val = v($this->params['form']['foo'], 'bar'); > > > On Apr 16, 4:56 pm, laeffe <[EMAIL PROTECTED]> wrote: > > > > 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 -~----------~----~----~----~------~----~------~--~---