首頁 > 後端開發 > php教程 > PHP數組和explode函數應用實例

PHP數組和explode函數應用實例

WBOY
發布: 2016-07-25 09:11:48
原創
1092 人瀏覽過

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

例1

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

  2. echo count($province);//数组成员个数
  3. echo "
    ";

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

  5. echo "嗯,真是个数组啊";
  6. }
  7. echo "
    ";

  8. for($index=0;$index

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

复制代码

例2

  1. //利用 explode 函数分割字符串到数组
  2. $source = "hello1,hello2,hello3,hello4,hello5";//按逗号分离字符串
  3. $hello = explode(',',$source);

  4. for($index=0;$index

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

复制代码

例3

  1. //函数挺实用的
  2. // 分隔符可以是斜线,点,或横线
  3. $date = "04/30/1973";
  4. list($month, $day, $year) = split ('[/.-]', $date);
  5. echo "Month: $month; Day: $day; Year: $year
    n";
  6. ?>
复制代码


來源:php.cn
本網站聲明
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn
熱門教學
更多>
最新下載
更多>
網站特效
網站源碼
網站素材
前端模板