"PHP strcmp()"의 두 판 사이의 차이

잔글 (봇: 자동으로 텍스트 교체 (-</source> +</syntaxhighlight>, -<source +<syntaxhighlight ))
 
(다른 사용자 한 명의 중간 판 하나는 보이지 않습니다)
3번째 줄: 3번째 줄:
* "바이너리 안전 문자열 비교"
* "바이너리 안전 문자열 비교"


<source lang='PHP'>
<syntaxhighlight lang='PHP'>
echo strcmp("aa","aa").PHP_EOL;
echo strcmp("aa","aa").PHP_EOL;
echo strcmp("aa","bb").PHP_EOL;
echo strcmp("aa","bb").PHP_EOL;
10번째 줄: 10번째 줄:
# -1
# -1
# 1
# 1
</source>
</syntaxhighlight>
: "a" - "a" = 97 - 97 = 0
: "a" - "a" = 97 - 97 = 0
: "a" - "b" = 97 - 98 = -1
: "a" - "b" = 97 - 98 = -1
: "b" - "a" = 98 - 97 = 1
: "b" - "a" = 98 - 97 = 1


<source lang='PHP'>
<syntaxhighlight lang='PHP'>
echo strcmp("hello","hello").PHP_EOL;
echo strcmp("hello","hello").PHP_EOL;
echo strcmp("hello","world").PHP_EOL;
echo strcmp("hello","world").PHP_EOL;
22번째 줄: 22번째 줄:
# -15
# -15
# 15
# 15
</source>
</syntaxhighlight>
: "h" - "h" = 104 - 104 = 0
: "h" - "h" = 104 - 104 = 0
: "h" - "w" = 104 - 119 = -15
: "h" - "w" = 104 - 119 = -15
: "w" - "h" = 119 - 104 = 15
: "w" - "h" = 119 - 104 = 15


<source lang='php'>
<syntaxhighlight lang='php'>
echo strcmp("aa","ab").PHP_EOL;
echo strcmp("aa","ab").PHP_EOL;
echo strcmp("ab","aa").PHP_EOL;
echo strcmp("ab","aa").PHP_EOL;
34번째 줄: 34번째 줄:
# -256
# -256
# 256
# 256
</source>
</syntaxhighlight>
: 256 * ( "a" - "b" ) = -256
: 256 × ( "a" - "b" ) = -256
: 256 * ( "b" - "a" ) = 256
: 256 × ( "b" - "a" ) = 256
: 256 * ( "a" - "c" ) = -512
: 256 × ( "a" - "c" ) = -512
: 256 * ( "c" - "a" ) = 512
: 256 × ( "c" - "a" ) = 512


<source lang='php'>
<syntaxhighlight lang='php'>
echo strcmp("aaa","aac").PHP_EOL;
echo strcmp("aaa","aac").PHP_EOL;
echo strcmp("aac","aaa").PHP_EOL;
echo strcmp("aac","aaa").PHP_EOL;
49번째 줄: 49번째 줄:
# -512
# -512
# 512
# 512
</source>
</syntaxhighlight>
: "a" - "c" = -2
: "a" - "c" = -2
: "c" - "a" = 2
: "c" - "a" = 2
: 256 * ( "a" - "c" ) = -512
: 256 × ( "a" - "c" ) = -512
: 256 * ( "c" - "a" ) = 512
: 256 × ( "c" - "a" ) = 512


==같이 보기==
==같이 보기==

2020년 11월 2일 (월) 02:58 기준 최신판

1 개요[ | ]

PHP strcmp()
  • "바이너리 안전 문자열 비교"
echo strcmp("aa","aa").PHP_EOL;
echo strcmp("aa","bb").PHP_EOL;
echo strcmp("bb","aa").PHP_EOL;
# 0
# -1
# 1
"a" - "a" = 97 - 97 = 0
"a" - "b" = 97 - 98 = -1
"b" - "a" = 98 - 97 = 1
echo strcmp("hello","hello").PHP_EOL;
echo strcmp("hello","world").PHP_EOL;
echo strcmp("world","hello").PHP_EOL;
# 0
# -15
# 15
"h" - "h" = 104 - 104 = 0
"h" - "w" = 104 - 119 = -15
"w" - "h" = 119 - 104 = 15
echo strcmp("aa","ab").PHP_EOL;
echo strcmp("ab","aa").PHP_EOL;
echo strcmp("aa","ac").PHP_EOL;
echo strcmp("ac","aa").PHP_EOL;
# -256
# 256
256 × ( "a" - "b" ) = -256
256 × ( "b" - "a" ) = 256
256 × ( "a" - "c" ) = -512
256 × ( "c" - "a" ) = 512
echo strcmp("aaa","aac").PHP_EOL;
echo strcmp("aac","aaa").PHP_EOL;
echo strcmp("aaaa","aaac").PHP_EOL;
echo strcmp("aaac","aaaa").PHP_EOL;
# -2
# 2
# -512
# 512
"a" - "c" = -2
"c" - "a" = 2
256 × ( "a" - "c" ) = -512
256 × ( "c" - "a" ) = 512

2 같이 보기[ | ]

3 참고[ | ]

문서 댓글 ({{ doc_comments.length }})
{{ comment.name }} {{ comment.created | snstime }}