欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

PHP7.1数据类型转换持续记录

程序员文章站 2022-04-09 20:28:57
1. 数值型与字符串运算 a. var_dump('one' + 5) # int(5), Warning: A non-numeric value encountered in... b. var_dump(5 / 'one') # float(INF),Warning: A non-numeri ......

1. 数值型与字符串运算

  a. var_dump('one' + 5)   #   int(5), Warning: A non-numeric value encountered in... 

  b. var_dump(5 / 'one')    #   float(INF),Warning: A non-numeric value encountered in... ,  Warning: Division by zero in...

  c. var_dump(6 / '2one')  #   int(3),Notice: A non-numeric value encountered in...

  d. var_dump(5 / '2one')  #   float(2.5), Notice: A non-numeric value encountered in...

  e. var_dump('5' % 2)   #   int(1)

  f.  var_dump('5.4' % 6)   #    int(5)

  g. var_dump('5.4one' % 6)  #    int(5), Notice: A non-numeric value encountered in...

  h. var_dump(5 / '3.3')     #    float(1.5151515151515)

  i.  var_dump(5 % '3.3')   #    int(2)

2. 数值型与字符串比较

  a. var_dump(5 == '5')    #     bool(true)

  b. var_dump(5 === '5')  #     bool(false)

  c. var_dump(5 < '5.4')   #      bool(true)