Simple arrangement of PHP arrays

小云云
Release: 2023-03-22 20:06:01
Original
1377 people have browsed it

This article mainly shares with you the simple arrangement of PHP arrays. You can find the function by defining the function variable name: function aMethod() { echo "I am a method";} function bMethod() { echo "I am another method"; }$myFunction = "aMethod";//Define the variable $myFunction(); //Since there are brackets after the variable, find the function function with the same name.

The array subscript can be specified

$arr = array(1=>"a","b","c","d");  echo $arr[3]; //打印c
Copy after login

The date for loop is an odd-numbered line output in bold font to traverse the date

 function boldTitle($inputText) {

         echo "<B>{$inputText}</B>";
       }

        date_default_timezone_set("UTC");
         
         $i = 0;

       for ($currentDate = date("U");date("l",$currentDate) != "Monday";$currentDate += (60*60*24)) {
          
          if ($i++%2==0) {

            echo "<li>".boldTitle(date("l",$currentDate))."</li>";

          }else {

              echo "<li>".date("l",$currentDate)."</li>";
          } 
        }
Copy after login


twodimensionalarray

  $cities = array(

    "华北地区"=>array("安徽","湖北","河南"),
    "西北地区"=>array("甘肃","兰州")
);

   echo "华北地区:".$cities[&#39;华北地区&#39;][0];
Copy after login

Related recommendations:

Detailed explanation of php array function

The above is the detailed content of Simple arrangement of PHP arrays. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template