PHP array definitions, values, and traversal

Source: Internet
Author: User
Tags echo date

<?PHP//common functions//Generate random numbers//echo rand (1,10);//two parameters to determine the range of random numbers//datetime function//var_dump (time ());//timestamp of Unix timestamp for the current time//date_default_ Timezone_set (' PRC '),//echo date ("Y-m-d h:i:s", Time ());//format date timestamp//echo date ("y-m-d h:i:s");//omit 2nd parameter get current time//array/ Features: can store any type of data, can be discontinuous, can be indexed, or can be associated//definition array (1)//$attr = Array (three-in-one); Define a simple indexed array//definition Array (2)//$attr [] = 1;//$attr [] = 2;//definition Array (3)$attr=Array("One" = "Hello", "three" =>10.9);/*$attr = Array ("Hello", "2" = "2222", "World");*///array value//echo $attr [0];//based on the index//echo $attr ["Three"];//value values based on key//traversal array//1.for loop for indexed arrays/*For ($i =0; $i <count ($attr), $i + +) {echo $attr [$i]. " <br> ";}*///2.foreach traversal, all applicable/*foreach ($attr as $v) {echo $v. <br> ";}*//*foreach ($attr as $k = + $v) {//echo $k. " --". $v."    <br> "; echo "{$k}--{$v}<br>";}*///3. Use each () and list () combination to iterate through the array/*Var_dump (each ($attr));//Returns the details of the current element in the array var_dump ($ATTR); Var_dump (each ($attr) );*///list ($a, $b, $c) = $attr;//Assign each element in the right-hand array to the list () argument lists, note: The right-hand array must contain an index/*while (list ($k, $v) =each ($attr) {echo "{$k}--{$v}<br>";}*///Var_dump ($attr);?>
View Code

PHP array definitions, values, and traversal

Related Article

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.