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

(새 문서: ==개요== ;PHP strcmp() * "바이너리 안전 문자열 비교" <source lang='PHP'> echo strcmp("aa","aa").PHP_EOL; echo strcmp("aa","bb").PHP_EOL; echo strcmp("bb","aa").PHP_EOL;...)
 
26번째 줄: 26번째 줄:
: "h" - "w" = 104 - 119 = -15
: "h" - "w" = 104 - 119 = -15
: "w" - "h" = 119 - 104 = 15
: "w" - "h" = 119 - 104 = 15
<source lang='php'>
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
</source>
: 256 * ( "a" - "b" ) = -256
: 256 * ( "b" - "a" ) = 256
: 256 * ( "a" - "c" ) = -512
: 256 * ( "c" - "a" ) = 512


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

2018년 6월 4일 (월) 22:48 판

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

2 같이 보기

3 참고

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