In php, how does one view the variable type, array elements, and object attributes?

Source: Internet
Author: User
I don't need to use {code...} because both of them are printed directly. I just like getting a string. Don't print it. How can I get it? No

Var_Dump($);print_r($ );

Because both of them are printed directly, I just like getting a string. Don't print it. How can this problem be solved?

Reply content:

No

Var_Dump($);print_r($ );

Because both of them are printed directly, I just like getting a string. Don't print it. How can this problem be solved?

Gettype (variable)

Viewing Arrays can only print
You can view the object
Get_class_methods ()
Get_class_vars ()

Gettype ()
You can also judge is_array (), is_bool (), is_float (), is_double (), is_integer (), is_null (), is_numeric (), is_object (), is_resource (), is_scalar () and is_string ()

Var str = var_export ($ arr, true );

Mixed var_export (mixed $ expression [, bool $ return])

This function returns the structure information about the variables passed to this function. It is similar to var_dump (). The difference is that the returned representation is legal PHP code.

You can set the second parameter of the function to TRUE to return the expression of the variable.

Whether it is viewing arrays, variables, or objectsVar_dump ()They are both the best tool and enough.

But I want to see the attributes and methods of the object. The answer above @ Zi ah,Get_class_methods ()AndGet_class_vars ()It will be a good method, but note thatThe two functions receive the class name..

However, you can useDebug_zval_dump ().

Of course, if you still thinkVar_dump ()Not enough. You can installXdebugExtension.

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.