note 46744 added to function.func-get-arg
| From: | dvogel at ssc dot wisc dot edu | Date: | Thu, 21 Oct 2004 21:54:52 +0000 |
| Subject: | note 46744 added to function.func-get-arg | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-78913@lists.php.net to get a copy of this message | ||
I've always wants a deferment or cascade operator so that I could use this expression:
$a = $b ## $c ## $d;
and everything to the right of the assignment operator would evaluate to the left-most value that is
not null. It is essentially a collapsed version of this:
if ($b) {
$a=$b;
} else {
if($c) {
$a=$c;
} else {
if ($d) {
$a = $d;
} else {
$a = null;
}
}
}
In leiu of this, I'm trying to make a function that takes a variable number of arguments and
returns the first that is not null. I wan't to use this on some large-ish arrays, so I'd
like to pass these by reference. However, call-time reference passing is disabled (and should be,
imo) in newer versions of PHP. I'd like suggestions on how to pass both references and values
to this function.
The only solution I can think of is setting variables to the reference of the array first. e.g.
$a = array( ... );
$b = 0;
$c = &a;
first_not_null($a, $b);
Does anyone know a better solution?
----
Manual Page -- http://www.php.net/manual/en/function.func-get-arg.php
Edit -- http://master.php.net/manage/user-notes.php?action=edit+46744
Delete -- http://master.php.net/manage/user-notes.php?action=delete+46744&report=yes
Reason: bad code -- http://master.php.net/manage/user-notes.php?action=delete+46744&report=yes&reason=bad+code
Reason: spam -- http://master.php.net/manage/user-notes.php?action=delete+46744&report=yes&reason=spam
Reason: useless example -- http://master.php.net/manage/user-notes.php?action=delete+46744&report=yes&reason=useless+example
Reason: contains commercial links -- http://master.php.net/manage/user-notes.php?action=delete+46744&report=yes&reason=contains+commercial+links
Reason: useless note -- http://master.php.net/manage/user-notes.php?action=delete+46744&report=yes&reason=useless+note
Reject -- http://master.php.net/manage/user-notes.php?action=reject+46744&report=yes
Search -- http://master.php.net/manage/user-notes.php