php explode() array_diff() implode()三個函數

來源:互聯網
上載者:User

$str = '數組1,數組2,數組3,數組4';
$array = explode(',',$str); //將規律字串存入數組

explode() 函數把字串分割為數組。

文法
explode(separator,string,limit)參數 描述
separator 必需。規定在哪裡分割字串。
string 必需。要分割的字串。
limit 可選。規定所返回的數組元素的最大數目。


$array = array_diff($array,array('數組2')); //刪除指定值的數組項

array_diff()函數比較兩個或多個數組,如果第一個數組中的鍵或值在第二個數組中並未出現,則以一個數組的形式返回這個未在第二個數組中出現的鍵和值。

syntax
文法
array_diff(array1,array2,array3...)

parameter
參數 description
描述
array1 required. the first array is the array that the others will be compared with
必要參數。指定第一個參與比較的基準數組
array2 required. an array to be compared with the first array
必要參數。指定與第一個數組相比較的第二個數組
array3 optional. an array to be compared with the first array
選擇性參數。指定與第一個數組相比較的第三個數組


$str = implode(',',$array); //將數組存為規律字串

implode() 函數把數組元素組合為一個字串。

文法
implode(separator,array)參數 描述
separator 可選。規定數組元素之間放置的內容。預設是 ""(Null 字元串)。
array 必需。要結合為字串的數組。

說明
雖然 separator 參數是可選的。但是為了向後相容,推薦您使用使用兩個參數。

echo $str;

 

 

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.