欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  后端开发

PHP数组和explode函数示例总结_PHP教程

程序员文章站 2024-02-06 16:41:28
...

PHP数组和explode函数示例总结

  有关php分割字符串explode函数的用法,使用explode函数将字符串分割到数组,这里给大家总结了几个示例,需要的朋友参考下。

  PHP数组和explode函数应用实例,供大家学习参考。

  例1:

  ?

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

$province = array("北京","上海","天津","重庆","河北","山西","内蒙古","辽宁","吉林","黑龙江","江苏","浙江","安徽","福建","江西","山东","河南","湖北","湖南","广东","广西","海南","四川","贵州","云南","*","陕西","甘肃","宁夏","青海","*","香港","澳门","*","其他");

echo count($province);//数组成员个数

echo "
";

if(is_array($province)){//检测变量是否是数组

echo "嗯,真是个数组啊";

}

echo "";

for($index=0;$index

echo $province[$index];

echo "";

}

?>

  例2:

  ?

1

2

3

4

5

6

7

8

9

//利用 explode 函数分割字符串到数组

$source = "hello1,hello2,hello3,hello4,hello5";//按逗号分离字符串

$hello = explode(',',$source);

for($index=0;$index

echo $hello[$index];echo "";

}

?>

  例3:

  ?

1

2

3

4

5

6

7

//函数挺实用的

// 分隔符可以是斜线,点,或横线

$date = "04/30/1973";

list($month, $day, $year) = split ('[/.-]', $date);

echo "Month: $month; Day: $day; Year: $year
\n";

?>

  以上所述就是本文的全部内容了,希望大家能够喜欢。

:更多精彩教程请关注帮客之家编程

www.bkjia.comtruehttp://www.bkjia.com/PHPjc/996753.htmlTechArticlePHP数组和explode函数示例总结 有关php分割字符串explode函数的用法,使用explode函数将字符串分割到数组,这里给大家总结了几个示例,需要的...