PHP array and explode function application examples for your learning reference.
Example 1:
-
-
$province = array("Beijing","Shanghai","Tianjin","Chongqing","Hebei","Shanxi","Inner Mongolia"," Liaoning","Jilin","Heilongjiang","Jiangsu","Zhejiang","Anhui","Fujian","Jiangxi","Shandong","Henan","Hubei","Hunan","Guangdong" ,"Guangxi","Hainan","Sichuan","Guizhou","Yunnan","Tibet","Shaanxi","Gansu","Ningxia","Qinghai","Xinjiang","Hong Kong"," Macau","Taiwan","Others"); - echo count($province);//Number of array members
- echo "
";
if(is_array ($province)){//Check whether the variable is an array
- echo "Well, it's really an array";
- }
- echo "";
for($index =0;$index
- echo $province[$index];
- echo "";
- }
- ?>
-
Copy code
Example 2:
-
-
- //Use the explode function to split the string into an array
- $source = "hello1,hello2,hello3,hello4,hello5";//Separate the string by commas
- $hello = explode(',',$source);
for($index=0;$index
- echo $hello[$index ];echo "";
- }
- ?>
-
Copy code
Example 3:
-
- //The function is very practical
- // The separator can be a slash, dot, or horizontal line
- $date = "04/30/1973";
- list($month, $day, $year) = split ('[/.-]', $date);
- echo "Month: $month; Day: $day; Year: $year
n";
- ?>
Copy code
|