PHP陣列和explode函式示例總結

2022-09-29 13:21:12 字數 788 閱讀 6839

例1:<?php $province = array("北京","上海","天津","重慶","河北","山西","內蒙古","遼寧","吉林","黑龍江","江蘇","浙江","安徽","福建","江西","山東","河南","湖北","湖南","廣東","廣西","海南",scjuyd"四川","貴州","雲南","**","陝西","甘肅","寧夏","青海","新疆","香港","澳門","台灣","其他");

echo count($province);//陣列成員個數

echo "

";if(is_array($province))

echo "";

for($index=0;$index";

}?>

例2:<?php //利用 explode 函式分割字串到數www.cppcns.com組

$source = "hello1,hello2,hel";//按逗號分離字串

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

for(";

}?>

例3:<?php //函式挺實用的

// 分隔scjuyd符可以是斜線,點,或橫線

$date = "04/30/1973";

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

echo "month: $month; day: $day; year: $year

\n";

?>

本文標題: php陣列和explode函式示例總結

本文位址:

PHP 函式explode和split的區別

之所以做這個,是因為這兩個函式的作用很像,都是把字串轉換成陣列。從下面的例子可以看出,生成的陣列是有對應的順序的。pizza piece1 piece2 piece3 piece4 piece5 piece6 pieces explode pizza echo pieces 0 piece1 ech...

PHP 函式explode和split的區別

之所以做這個,是因為這兩個函式的作用很像,都是把字串轉換成陣列。從下面的例子可以看出,生成的陣列是有對應的順序的。pizza piece1 piece2 piece3 piece4 piece5 piece6 pieces explode pizza echo pieces 0 piece1 ech...

explode 函式和implode 函式

explode 函式把字串分割為陣列 explode separator,string,limit separator 必需。規定在 分割字串。string 必需。要分割的字串。limit 可選。規定所返回的陣列元素的最大數目。例子 str hello world.it s a beautiful ...