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

35번째 줄: 35번째 줄:
# 256
# 256
</source>
</source>
: 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'>
<source lang='php'>
52번째 줄: 52번째 줄:
: "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


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

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

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 }}