Home > Article > Backend Development > Simple arrangement of PHP arrays
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
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>"; } }
twodimensionalarray
$cities = array( "华北地区"=>array("安徽","湖北","河南"), "西北地区"=>array("甘肃","兰州") ); echo "华北地区:".$cities['华北地区'][0];
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!