[php] implode 函數返回一個字符串的內容陣列。

例如
<?php
$arr = array('Hello','World!','Beautiful','Day!');
echo implode(" ",$arr);
?>

輸出
Hello World! Beautiful Day!


穿曲範例
Example #1 implode() example
<?php

$array = array('lastname', 'email', 'phone');
$comma_separated = implode(",", $array);

echo $comma_separated; // lastname,email,phone

// Empty string when using an empty array:
var_dump(implode('hello', array())); // string(0) ""

?>


其它範例:(類似query_string函數)
function implode_get() {
    $first = true;
    $output = '';
    foreach($_GET as $key => $value) {
        if ($first) {
            $output = '?'.$key.'='.$value;
            $first = false;
        } else {
            $output .= '&'.$key.'='.$value;   
        }
    }
    return $output;
}

echo '<form action='.$_SERVER['PHP_SELF'].implode_get().' method=post>';
?>


arrow
arrow
    全站熱搜

    stockwfj3 發表在 痞客邦 留言(0) 人氣()