Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Can php output the array directly?

2025-01-17 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)05/31 Report--

This article mainly introduces the relevant knowledge of "whether php can output the array directly". The editor shows you the operation process through the actual case. The operation method is simple, fast and practical. I hope that this article "whether php can directly output the array" can help you solve the problem.

Php can directly output the array, there are two ways: 1, with print_r (), you can output array content and structure, and will display keys and elements in a certain format, syntax "print_r (array)"; 2, with var_dump (), output content and structure, and display element types, syntax "var_dump (array)".

Operating environment of this tutorial: windows7 system, PHP7.1 version, DELL G3 computer

Php can output arrays directly.

Two functions are built into php to output arrays directly:

Print_r () function

Var_dump () function

1. Use print_r () to output the array

The print_r () function is used to print variables in a more understandable form. Through the print_r () function, you can output the contents and structure of the entire array, and display keys and elements in a certain format.

Output result:

Array ([0] = > Array ([name] = > Zhang San [age] = > 25 [sex] = > male) [1] = > Array ([name] = > Li Si [age] = > 21 [sex] = > male) [2] = > Array ([name] = > Nana [age] = > 22 [sex] = > female)

Do you feel that the output is too long to make use of reading? You can add a piece of code "echo';" before the print_r () output statement:

In this way, the output is easier to read, and the output is:

2. Use var_dump () to output the array

Similar to the print_r () function, the var_dump () function can also output the data content and structure of the entire array. However, var_dump () is more powerful than print_r (), which can print multiple variables at the same time and give the type information of the variables.

The var_dump () function outputs information about variables (types and values). When you output an array, the array recursively expands the value and displays its structure by indentation.

Output result:

Description:

The print_r () and var_dump () functions are generally used by debuggers, and more often, echo is used to output specific array unit values.

This is the end of the introduction on "whether php can output arrays directly". Thank you for reading. If you want to know more about the industry, you can follow the industry information channel. The editor will update different knowledge points for you every day.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report