PHP数组和explode函数示例总结

时间:2021-05-26

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

例1:

<?php$province = array("北京","上海","天津","重庆","河北","山西","内蒙古","辽宁","吉林","黑龙江","江苏","浙江","安徽","福建","江西","山东","河南","湖北","湖南","广东","广西","海南","四川","贵州","云南","西藏","陕西","甘肃","宁夏","青海","新疆","香港","澳门","台湾","其他");echo count($province);//数组成员个数echo "<br/>";if(is_array($province)){//检测变量是否是数组 echo "嗯,真是个数组啊";}echo "</br>";for($index=0;$index<count($province);$index++){//数组循环echo $province[$index];echo "</br>";}?>

例2:

<?php//利用 explode 函数分割字符串到数组$source = "hello1,hello2,hello3,hello4,hello5";//按逗号分离字符串$hello = explode(',',$source);for($index=0;$index<count($hello);$index++){echo $hello[$index];echo "</br>";}?>

例3:

<?php//函数挺实用的// 分隔符可以是斜线,点,或横线$date = "04/30/1973";list($month, $day, $year) = split ('[/.-]', $date);echo "Month: $month; Day: $day; Year: $year<br />\n";?>

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

声明:本页内容来源网络,仅供用户参考;我单位不保证亦不表示资料全面及准确无误,也不保证亦不表示这些资料为最新信息,如因任何原因,本网内容或者用户因倚赖本网内容造成任何损失或损害,我单位将不会负任何法律责任。如涉及版权问题,请提交至online#300.cn邮箱联系删除。

相关文章