PHP 에서 배열값의 양쪽 공백 제거 방법
페이지 정보
본문
ㅁ PHP 에서 array_map 과 trim 을 이용해서 배열 값의 양쪽 공백을 제거하는 방법이다.
array_map 을 이용한다.
[code]
<?php
$fruit = array(' apple ','banana ', ' , ', ' cranberry ');
$trimmed_array=array_map('trim',$fruit);
print_r($trimmed_array);
?>
[/code]
* 출처 : https://stackoverflow.com/questions/5762439/how-to-trim-white-spaces-of-array-values-in-php
ㅁ 참고로, PHP 공식 사이트에는 아래와 같은 방법도 나와 있다.
[code]
<?php
function trim_value(&$value)
{
$value = trim($value);
}
$fruit = array('apple','banana ', ' cranberry ');
var_dump($fruit);
array_walk($fruit, 'trim_value');
var_dump($fruit);
?>
[/code]
http://php.net/manual/kr/function.trim.php
ㅁ trim 이외에 다른 함수들도 사용이 가능하다.
[code]
<?php
$PAY = array_map('trim', $ret);
$PAY = array_map('strip_tags', $PAY);
$PAY = array_map('get_search_string', $PAY);
?>
[/code]
https://github.com/gnuboard/youngcart5/commit/6d3a89f0b9828a322b67f443fbc224ba762abc9f
array_map 을 이용한다.
[code]
<?php
$fruit = array(' apple ','banana ', ' , ', ' cranberry ');
$trimmed_array=array_map('trim',$fruit);
print_r($trimmed_array);
?>
[/code]
* 출처 : https://stackoverflow.com/questions/5762439/how-to-trim-white-spaces-of-array-values-in-php
ㅁ 참고로, PHP 공식 사이트에는 아래와 같은 방법도 나와 있다.
[code]
<?php
function trim_value(&$value)
{
$value = trim($value);
}
$fruit = array('apple','banana ', ' cranberry ');
var_dump($fruit);
array_walk($fruit, 'trim_value');
var_dump($fruit);
?>
[/code]
http://php.net/manual/kr/function.trim.php
ㅁ trim 이외에 다른 함수들도 사용이 가능하다.
[code]
<?php
$PAY = array_map('trim', $ret);
$PAY = array_map('strip_tags', $PAY);
$PAY = array_map('get_search_string', $PAY);
?>
[/code]
https://github.com/gnuboard/youngcart5/commit/6d3a89f0b9828a322b67f443fbc224ba762abc9f
추천0
댓글목록
등록된 댓글이 없습니다.