Get the App
SLTechnology News&Howtos  ›  Development  › 

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

Shulou Source: shulou.com Published: 2022-06-01 02:37:36 10月24日 Update

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!

Tags: Array function variable article subscript content unit character sequence index association not much between most number more knowledge scope industry information Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Microsoft macOS MariaDB Xiaomi vpn