$myAry = array();
// I want to return the array's name.
// something like
echo $myAry.name;
// Should print "$myAry".
Thanks,
$myAry = array();
// I want to return the array's name.
// something like
echo $myAry.name;
// Should print "$myAry".
Thanks,
But if you type $myAry
you already know the name of the variable. What is
it you are trying to achieve?
If you absolutely must know the identity of your variables...
function my_function ($my_array) {
$caller_info = array_shift(debug_backtrace());
$lines = file($caller_info['file']);
$line = $lines[$caller_info['line'] - 1];
if(preg_match('/my_function\\s*\\(\$(\\w+)/', $line, $matches)) {
$name_of_my_array = $matches[1];
echo $name_of_my_array;
}
}
Is this what you want?
You can get argument name like this:
function get_function ($my_array) {
$f = new ReflectionFunction($my_array);
$result = array();
foreach ($f->getParameters() as $param) {
$result[] = $param->name;
}
return $result;
}
function sayHello($helloWorlds){
echo $helloWorld;
}
print_r(get_function('sayHello'));;
//Output
Array ( [0] => helloWorlds )
$array = array('name12'); $comma_separated = implode(",", $array);
echo $comma_separated; // name12
// Empty string when using an empty array:
var_dump(implode('hello', array())); // string(0) ""