Originally Posted by vesselin
In PHP several variables can share the same object. For example:
$customer = array('sefdsf','sdfsdf','sdfsdf');
$customer_2 = $customer;
$customer_3 = $customer;
All the 3 variables $customer, $customer_2 and $customer_3 will not only contain the same value, but they will also point internally to the same object. So it is not possible to tell definitely which variable is the owner of the array.
[/CODE]
|
This is actually incorrect, these variables are all completely different, however they are all the same. $customer is not referenced in any way, thus they do not point to the same object they simply create clones of it.
$customer_2 = &$customer.
means it creates a pointer to the other variable, and doesnt simply clone it. So if $customer_2 is changed so is $customer.
Anyway, enough of the lesson...
To OP:
Salathe's code would of worked, if you know how to use it, to simplify it:
PHP Code:
$cutomer = array('sefdsf','sdfsdf','sdfsdf');
print vname($customer);
//Should print "customer" if the function works :)
function vname(&$var, $scope = false, $prefix = 'unique', $suffix = 'value')
{
$vals = ($scope) ? $scope : $GLOBALS;
$old = $var;
$var = $new = $prefix . rand() . $suffix;
$vname = FALSE;
foreach($vals as $key => $val)
if($val === $new)
$vname = $key;
$var = $old;
return $vname;
}