|
Posted by Janwillem Borleffs on 06/02/05 17:25
Ewoud Dronkert wrote:
> On Thu, 02 Jun 2005 13:09:31 +0100, James wrote:
>
>>Someone has wrote some info on how to do this here, as a user
>>contributed note: http://php.net/variables
>>[...] credit goes to lucas karisny.
>
>
> Yeah. If you have no need for local scope you can trim the function a
> little. Also with simpler unique value generation:
>
> function f( &$x )
> {
> $old = $x;
> $x = md5( uniqid( mt_rand(), TRUE ) );
> foreach ( $GLOBALS as $k => $v )
> if ( $v === $x )
> {
> $x = $old;
> return $k;
> }
> return FALSE;
> }
>
> $a = 'test';
> $b = 'test';
> echo f( $a ); // 'a'
> echo f( $b ); // 'b'
>
>
$x should be assigned its old value before returning FALSE; otherwise it
will be modified when the function failed...
JW
Navigation:
[Reply to this message]
|