New php users ask about variable output

Source: Internet
Author: User
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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.