PHP數(shù)組和explode函數(shù)示例總結
更新時間:2015年05月08日 11:34:22 投稿:hebedich
有關php分割字符串explode函數(shù)的用法,使用explode函數(shù)將字符串分割到數(shù)組,這里給大家總結了幾個示例,需要的朋友參考下。
PHP數(shù)組和explode函數(shù)應用實例,供大家學習參考。
例1:
<?php
$province = array("北京","上海","天津","重慶","河北","山西","內蒙古","遼寧","吉林","黑龍江","江蘇","浙江","安徽","福建","江西","山東","河南","湖北","湖南","廣東","廣西","海南","四川","貴州","云南","西藏","陜西","甘肅","寧夏","青海","新疆","香港","澳門","臺灣","其他");
echo count($province);//數(shù)組成員個數(shù)
echo "<br/>";
if(is_array($province)){//檢測變量是否是數(shù)組
echo "嗯,真是個數(shù)組啊";
}
echo "</br>";
for($index=0;$index<count($province);$index++){//數(shù)組循環(huán)
echo $province[$index];
echo "</br>";
}
?>
例2:
<?php
//利用 explode 函數(shù)分割字符串到數(shù)組
$source = "hello1,hello2,hello3,hello4,hello5";//按逗號分離字符串
$hello = explode(',',$source);
for($index=0;$index<count($hello);$index++){
echo $hello[$index];echo "</br>";
}
?>
例3:
<?php
//函數(shù)挺實用的
// 分隔符可以是斜線,點,或橫線
$date = "04/30/1973";
list($month, $day, $year) = split ('[/.-]', $date);
echo "Month: $month; Day: $day; Year: $year<br />\n";
?>
以上所述就是本文的全部內容了,希望大家能夠喜歡。
您可能感興趣的文章:
- PHP中shuffle數(shù)組值隨便排序函數(shù)用法
- JavaScript中實現(xiàn)PHP的打亂數(shù)組函數(shù)shuffle實例
- php數(shù)組函數(shù)序列 之shuffle()和array_rand() 隨機函數(shù)使用介紹
- PHP數(shù)組函數(shù)array_multisort()用法實例分析
- PHP常見數(shù)組函數(shù)用法小結
- php數(shù)組函數(shù)array_key_exists()小結
- PHP中使用array函數(shù)新建一個數(shù)組
- php 利用array_slice函數(shù)獲取隨機數(shù)組或前幾條數(shù)據(jù)
- php使用array_search函數(shù)實現(xiàn)數(shù)組查找的方法
- PHP使用in_array函數(shù)檢查數(shù)組中是否存在某個值
- PHP數(shù)組相關函數(shù)匯總
- php使用gettimeofday函數(shù)返回當前時間并存放在關聯(lián)數(shù)組里
- php訪問數(shù)組最后一個元素的函數(shù)end()用法
- PHP函數(shù)shuffle()取數(shù)組若干個隨機元素的方法分析
相關文章
zen cart實現(xiàn)訂單中增加paypal中預留電話的方法
這篇文章主要介紹了zen cart實現(xiàn)訂單中增加paypal中預留電話的方法,涉及數(shù)據(jù)庫字段的添加、ipn_create_order_array函數(shù)的修改及后臺模型文件的相應修改技巧,需要的朋友可以參考下2016-07-07
PHP中Laravel 關聯(lián)查詢返回錯誤id的解決方法
這篇文章主要介紹了Laravel 關聯(lián)查詢返回錯誤id的解決方法,非常不錯,具有參考借鑒價值,需要的朋友參考下吧2017-04-04
實例(Smarty+FCKeditor新聞系統(tǒng))
實例(Smarty+FCKeditor新聞系統(tǒng))...2007-01-01

