Why does “echo strcmp('60', '100');” in php output 5?

你。 提交于 2019-12-03 06:47:50

strcmp() returns the difference of the first non-matching character between the strings.

6 - 1 is 5.

When you look at it, you are probably not seeing the characters or digits—just the numbers

Madara Uchiha

Because strcmp() stops at the first difference it finds. Hence the difference between the ASCII value of '1' and the ASCII value of '6'

6 is 5 "larger" than 1. This is lexical comparison. The first character is different, that's where the comparison stops.

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!