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

How to quickly create arrays through range () and compact () by PHP

2025-03-28 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/01 Report--

Editor to share with you how PHP through range () and compact () to quickly create arrays, I believe that most people do not know much, so share this article for your reference, I hope you can learn a lot after reading this article, let's go to know it!

Quickly create through range () and compact ()

/ / range () quickly create a subscript continuous index array / * * range () function * array range (mixed $start, mixed $limit [, number $step=1]) * description: create a subscript continuous index array containing specified range units * start: the first value of the sequence * limit: the value that the sequence ends with limit * step: if the value of step is given, it will be used as the step value between cells if not specified Default is 1 * * add: * string chr (int $value): convert numbers as ASCII into characters * int ord (string $value): ASCII * / $arr = range (1,5) of the output characters Print_r ($arr); / / Array ([0] = > 1 [1] = > 2 [2] = > 3 [3] = > 4 [4] = > 5) $arr = range ('await,' baked,'c'); print_r ($arr); / / Array ([0] = > a [1] = > b [2] = > c) echo chr (90), "\ n"; / / Zecho ord ('z'), "\ n" / / 122//compact () quickly create associative arrays / * * compact () function * array compact (mixed $varname [, mixed $...]) * description: create an array, including variable names and their values * * add: * list ($var1, $var2...): assign the values in the array to some variables * / $username = 'zhao';$age =' 22 variables $arr = compact ('username',' age', 'email'); / / generate associative array / / Array quickly by putting existing variable names in the function ([username] = > zhao [age] = > 22 [email] = > wangzhao_hb@126.com) print_r ($arr); list ($a, $b, $c) = array (1, 2, 3)

The value of echo "an is {$a}, the value of b is {$b}, the value of c is {$c}", "\ n"; / / an is 1, b is 2, c is 3

That's all of the article "how PHP creates arrays quickly through range () and compact (). Thank you for reading!" I believe we all have a certain understanding, hope to share the content to help you, if you want to learn more knowledge, welcome to follow the industry information channel!

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