Examples of PHP arrays and explode functions are summarized _php examples

Source: Internet
Author: User
Tags explode

PHP array and explode function application examples, for everyone to learn the reference.

Example 1:

<?php
$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", "Macao", "Taiwan", "other");
echo count ($province);//number of array members
echo "<br/>";

if (Is_array ($province)) {//detect whether the variable is an array of
  echo "Well, that's a number.";
}
echo "</br>";

For ($index =0 $index <count ($province); $index + +) {//array loop
echo $province [$index];
echo "</br>";
>

Example 2:

<?php
//using Explode function to split string to array
$source = "HELLO1,HELLO2,HELLO3,HELLO4,HELLO5";//comma-separated string
$hello = Explode (', ', $source);

For ($index =0 $index <count ($hello); $index + +) {
echo $hello [$index];echo] </br>
}
? >

Example 3:

<?php
//function quite practical
//separator can be diagonal, dot, or horizontal line
$date = "04/30/1973";
List ($month, $day, $year) = Split (' [/.-] ', $date);
echo "Month: $month; Day: $day; Year: $year <br/>\n ";
? >

The above mentioned is the entire content of this article, I hope you can enjoy.

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.