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 :: spatie/laravel-activitylog display only changed data 
Php :: laravel where in query builder 
Php :: php inner join array 
Php :: php fn closure 
Php :: how to logout in phpmyadmin 
Php :: oop php 
Php :: require password confirm laravel 
Php :: php is datetime 
Php :: laravel route namespace 
Php :: php match expression 
Php :: query builder codeigniter 
Php :: Code to check Check whether a year is leap year or not 
Php :: php ternary operator good example 
Php :: laravel wherein like 
Php :: xampp downgrade php 
Php :: with relation laravel 
Php :: -with() in laravel 
Php :: create trait in laravel 8 
Php :: php array form 
Php :: include vendor/autoload.php 
Php :: Remove the additional notes area from the WooCommerce checkout 
Php :: menyimpan get di laravel 
Php :: php radian to cosine 
Php :: Drupal 8 / 9 entityTypeManager get multiple comments by cid 
Php :: laravel session wont update 
Php :: What does this mean in PHP: - or = 
Php :: random record get with pagination in karavel 8 
Php :: php limit results by 30 days 
Php :: unisharp laravel, Tai anh? 
Php :: Composer detected issues in your platform: Your Composer dependencies require a PHP version "= 7.4.0". 
ADD CONTENT
Topic
Content
Source link
Name
5+4 =