Search
 
SCRIPT & CODE EXAMPLE
 

PHP

php get variable by string name

${$variableName} or $$variableName;

//example:

$variableName = 'foo';
$foo = 'bar';

// The following are all equivalent, and all output "bar":
echo $foo;
echo ${$variableName};
echo $$variableName;
Comment

php get variable name as a string

function print_var_name(){
    // read backtrace
    $bt   = debug_backtrace();
    // read file
    $file = file($bt[0]['file']);
    // select exact print_var_name($varname) line
    $src  = $file[$bt[0]['line']-1];
    // search pattern
    $pat = '#(.*)'.__FUNCTION__.' *?( *?(.*) *?)(.*)#i';
    // extract $varname from match no 2
    $var  = preg_replace($pat, '$2', $src);
    // print to browser
    echo trim($var);
}
Comment

PREVIOUS NEXT
Code Example
Php :: php Program to check if a given year is leap year 
Php :: session start php 
Php :: php get filename 
Php :: laravel datatable addColumn not working 
Php :: how create page 419 in laravel 
Php :: PHP Fatal error: Allowed memory size of 1610612736 bytes exhausted 
Php :: laravel filesystem link 
Php :: php round nearest half 
Php :: array join pgp 
Php :: select2 on modal 
Php :: laravel get all request parameters 
Php :: how to set optional third parameter in routes of codeigniter 
Php :: position for ip 
Php :: php - = 
Php :: close connection pdo 
Php :: echo php in html 
Php :: spaceship operator php 
Php :: install phpmyadmin ubuntu 18.04 
Php :: $ is not define in laravel 
Php :: set cookie on button click php or js 
Php :: codeigniter4 route optional parameter 
Php :: symfony form submit on refresh 
Php :: Using the PHPExcel library to read an Excel file and transfer the data into a database 
Php :: Laravel check for constraint violation 
Php :: laravel edit form modal example 
Php :: carbon date time laravel 
Php :: laravel custom abort message 
Php :: oops concepts in php 
Php :: php input onchange 
Php :: namespace in php 
ADD CONTENT
Topic
Content
Source link
Name
8+7 =