Home >Backend Development >PHP Tutorial >PHP array and explode function application examples

PHP array and explode function application examples

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOriginal
2016-07-25 09:11:481127browse

PHP array and explode function application examples for your learning reference.

Example 1:

  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");

  2. echo count($province);//Number of array members
  3. echo "
    ";

  4. if(is_array ($province)){//Check whether the variable is an array

  5. echo "Well, it's really an array";
  6. }
  7. echo "
    ";

  8. for($index =0;$index

  9. echo $province[$index];
  10. echo "
    ";
  11. }
  12. ?>

Copy code

Example 2:

  1. //Use the explode function to split the string into an array
  2. $source = "hello1,hello2,hello3,hello4,hello5";//Separate the string by commas
  3. $hello = explode(',',$source);

  4. for($index=0;$index

  5. echo $hello[$index ];echo "
    ";
  6. }
  7. ?>

Copy code

Example 3:

  1. //The function is very practical
  2. // The separator can be a slash, dot, or horizontal line
  3. $date = "04/30/1973";
  4. list($month, $day, $year) = split ('[/.-]', $date);
  5. echo "Month: $month; Day: $day; Year: $year
    n";
  6. ?>
Copy code


Statement:
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