쪼개기 한판 > 그누4 팁자료실

그누4 팁자료실

그누보드4와 관련된 팁을 여러분들과 함께 공유하세요.
나누면 즐거움이 커집니다.

쪼개기 한판 정보

쪼개기 한판

본문

<?

// 제가 써먹을려다 보니.....
// 출처 http://au3.php.net/manual/en/function.implode.php

$array = array('test1', 'test2', 'test3');
$comma_separated = implode("|", $array);

echo $comma_separated;

echo '<br><br><br>';

$total  =  count($array);  // array count

echo '<br><br><br>';
$comma_separated = explode("|", $comma_separated);

for($i=0;$i<$total;++$i){
echo $comma_separated[$i];
echo '<br>';
}


///////////////////////////////////////////////////
echo '<br><br><br>';

function text_array($array) {
  switch (count($array)) {
  case 0:
    return '';
  case 1:
    return array_pop($array);
  default:
    $last = array_pop($array);
    return implode('|', $array) . '|' . $last;
  }
}


$array = array('test1', 'test2', 'test3','test4');
echo text_array($array);
echo '<br><br><br>';

///////////////////////////////////////////

function text_array2($array) {
  switch (count($array)) {
  case 0:
    return '';
  case 1:
    return array_pop($array);
  default:
    $last = array_pop($array);
    return implode('|', $array).'/'.$last;  // 요기..........포인트
  }
}

$array = array('test1', 'test2', 'test3','test4');
echo text_array2($array);
echo '<br><br><br>';

/////////////////////////////////////






function implode_with_keys($array, $glue, $is_query = false) {
  if($is_query == true) {
      return str_replace(array('[', ']', '&'), array('%5B', '%5D', '&amp;'), http_build_query($array));

  } else {
      return urldecode(str_replace("&", $glue, http_build_query($array)));

  }

}



echo implode_with_keys(array('a' => 'foo bar', 'b' => 'more text'), '|');


echo '<br><br><br>';

///////////////////////////////////////////////////////////////

function english_list($array, $oxfordComma=0)
{
  $optionalComma = ( $oxfordComma ) ? "," : "";
  $str = "";
  $size = count( $array );
  $i = 0;
  foreach ( $array as $item ) {
  $str .= $item;
  $i++;
  if ( $i < $size - 1) $str .= ", ";
  elseif ( $i == $size - 1) $str .= $optionalComma." and ";
  }
  return $str;
}

// test the comma separated list function
echo english_list( array(), 1 )."<br>";
echo english_list( array("foo"), 1 )."<br>";
echo english_list( array("foo", "bar"), 0 )."<br>";
echo english_list( array("a" => "foo", "b" => "bar", "c" => "foobar"), 1 )."<br>";
echo english_list( array("foo", "bar", "foobar", "barfoo"), 0 )."<br>";

echo '<br><br><br>';

///////////////////////////////////////////////////////////

$val[1]="one";
$val[2]="two";
$val[0]="zero";
ksort($val);    // 포인트
echo implode("|",$val);


///////////////////////////////////////////////////////////
echo '<br><br><br>';



?>
추천
0
  • 복사

댓글 3개

© SIRSOFT
현재 페이지 제일 처음으로