A beginner in php asks a variable output question and asks a question about the variable output display!
Now there is the variable $ ssdd = array (a => 2, B => 3); I want to output $ ssdd in the debugging process, instead of the value of a or B in it.
What function output is used.
If you directly echo $ ssdd, the output array
If print_f ($ ssdd), the output array
How can I output the name of $ ssdd?
Reply to discussion (solution)
Var_dump () or print_r ();
Var_export ()
Var_dump () or print_r ();
Var_export ()
Thanks for your attention. these are all the elements of the array that output a equals 1 and B equals 2, which is not my purpose,
My goal is what is the name of my array? Output $ ssdd
Var_dump () or print_r ();
Var_export ()
Thanks for your attention. these are all the elements of the array that output a equals 1 and B equals 2, which is not my purpose,
My goal is what is the name of my array? Output $ ssdd
Output ssdd?
$ Is only the symbol for declaring Variables. the actual variable name is ssdd and can be obtained by get_defined_vars ().
Echo "$ ssdd ";
$ Is only the symbol for declaring Variables. the actual variable name is ssdd and can be obtained by get_defined_vars ().
Function get_variable_name (& $ var, $ scope = NULL) {if (NULL = $ scope) {$ scope = $ GLOBALS;} $ tmp = $ var; $ var = "tmp_exists _". mt_rand (); $ name = array_search ($ var, $ scope, TRUE); $ var = $ tmp; return $ name;} echo get_variable_name ($ ssdd ); // output ssdd, which I do not understand
$ Is only the symbol for declaring Variables. the actual variable name is ssdd and can be obtained by get_defined_vars ().
Function get_variable_name (& $ var, $ scope = NULL) {if (NULL = $ scope) {$ scope = $ GLOBALS;} $ tmp = $ var; $ var = "tmp_exists _". mt_rand (); $ name = array_search ($ var, $ scope, TRUE); $ var = $ tmp; return $ name;} echo get_variable_name ($ ssdd ); // output ssdd, which I do not understand
To obtain custom variables, you must support Global Arrays. it takes some time to query the page, that is, to conveniently debug the output variable name.
All functions I have customized
Function var_out ($ var, $ char ){
/*
* $ Var is still the variable to be output, and $ char is passed as a variable name string
* Below is the simple output code. in the past, I always wanted to use a passed variable in the function to output the function. I just wanted to upload more parameters!
*/
If (is_array ($ var ){
Echo 'variable name: '. $ char .'
';
Print_r ($ var );
}
Else echo 'variable name:'. $ char. '='. $ var .'
;
}
Location call
Var_out ($ ssdd, '$ ssdd ');
The output result is an array named $ ssdd, and the result is printed.