PHP内核探索:变量类型的转换
内容导读
互联网集市收集整理的这篇技术教程文章主要介绍了PHP内核探索:变量类型的转换,小编现在分享给大家,供广大互联网技能从业者学习和参考。文章包含9677字,纯文字阅读大概需要14分钟。
内容图文
![PHP内核探索:变量类型的转换](/upload/InfoBanner/zyjiaocheng/156/b6677156a9ce4653a4b643bc88ff8795.jpg)
PHP是弱类型的动态语言,我们已经知道了PHP的变量都存放在一个名为ZVAL的容器中, ZVAL包含了变量的类型和各种类型变量的值。 PHP中的变量不需要显式的数据类型定义,可以给变量赋值任意类型的数据, PHP变量之间的数据类型转换有两种:隐式和显式转换。
隐式类型转换
隐式类型转换也被称为自动类型转换,是指不需要程序员书写代码,由编程语言自动完成的类型转换。 在PHP中,我们经常遇到的隐式转换有:
1.直接的变量赋值操作
在PHP中,直接对变量的赋值操作是隐式类型转换最简单的方式,也是我们最常见的一种方式,或许我们已经习以为常,从而没有感觉到变量的变化。 在直接赋值的操作中,变量的数据类型由赋予的值决定,即左值的数据类型由右值的数据类型决定。 比如,当把一个字符串类型的数据赋值给变量时,不管该变量以前是什么类型的变量,此时该变量就是一个字符串类型的变量。 看一段代码:
$string = "To love someone sincerely means to love all the people, to love the world and life, too."$integer = 10;
$string = $integer;
上面的代码,当执行完第三行代码,string<spanArial Unicode MS', serif; font-size: 73%; font-style: normal; font-weight: normal;">变<spanArial Unicode MS', serif; font-size: 73%; font-style: normal; font-weight: normal;">量<spanArial Unicode MS', serif; font-size: 73%; font-style: normal; font-weight: normal;">的<spanArial Unicode MS', serif; font-size: 73%; font-style: normal; font-weight: normal;">类<spanArial Unicode MS', serif; font-size: 73%; font-style: normal; font-weight: normal;">型<spanArial Unicode MS', serif; font-size: 73%; font-style: normal; font-weight: normal;">就<spanArial Unicode MS', serif; font-size: 73%; font-style: normal; font-weight: normal;">是<spanArial Unicode MS', serif; font-size: 73%; font-style: normal; font-weight: normal;">一<spanArial Unicode MS', serif; font-size: 73%; font-style: normal; font-weight: normal;">个<spanArial Unicode MS', serif; font-size: 73%; font-style: normal; font-weight: normal;">整<spanArial Unicode MS', serif; font-size: 73%; font-style: normal; font-weight: normal;">形<spanArial Unicode MS', serif; font-size: 73%; font-style: normal; font-weight: normal;">了<spanArial Unicode MS', serif; font-size: 73%; font-style: normal; font-weight: normal;">。<spanArial Unicode MS', serif; font-size: 73%; font-style: normal; font-weight: normal;">通<spanArial Unicode MS', serif; font-size: 73%; font-style: normal; font-weight: normal;">过VLD<spanArial Unicode MS', serif; font-size: 73%; font-style: normal; font-weight: normal;">扩<spanArial Unicode MS', serif; font-size: 73%; font-style: normal; font-weight: normal;">展<spanArial Unicode MS', serif; font-size: 73%; font-style: normal; font-weight: normal;">可<spanArial Unicode MS', serif; font-size: 73%; font-style: normal; font-weight: normal;">以<spanArial Unicode MS', serif; font-size: 73%; font-style: normal; font-weight: normal;">查<spanArial Unicode MS', serif; font-size: 73%; font-style: normal; font-weight: normal;">到<spanArial Unicode MS', serif; font-size: 73%; font-style: normal; font-weight: normal;">第<spanArial Unicode MS', serif; font-size: 73%; font-style: normal; font-weight: normal;">三<spanArial Unicode MS', serif; font-size: 73%; font-style: normal; font-weight: normal;">次<spanArial Unicode MS', serif; font-size: 73%; font-style: normal; font-weight: normal;">赋<spanArial Unicode MS', serif; font-size: 73%; font-style: normal; font-weight: normal;">值<spanArial Unicode MS', serif; font-size: 73%; font-style: normal; font-weight: normal;">操<spanArial Unicode MS', serif; font-size: 73%; font-style: normal; font-weight: normal;">作<spanArial Unicode MS', serif; font-size: 73%; font-style: normal; font-weight: normal;">的<spanArial Unicode MS', serif; font-size: 73%; font-style: normal; font-weight: normal;">中<spanArial Unicode MS', serif; font-size: 73%; font-style: normal; font-weight: normal;">间<spanArial Unicode MS', serif; font-size: 73%; font-style: normal; font-weight: normal;">代<spanArial Unicode MS', serif; font-size: 73%; font-style: normal; font-weight: normal;">码<spanArial Unicode MS', serif; font-size: 73%; font-style: normal; font-weight: normal;">及<spanArial Unicode MS', serif; font-size: 73%; font-style: normal; font-weight: normal;">操<spanArial Unicode MS', serif; font-size: 73%; font-style: normal; font-weight: normal;">作<spanArial Unicode MS', serif; font-size: 73%; font-style: normal; font-weight: normal;">数<spanArial Unicode MS', serif; font-size: 73%; font-style: normal; font-weight: normal;">的<spanArial Unicode MS', serif; font-size: 73%; font-style: normal; font-weight: normal;">类<spanArial Unicode MS', serif; font-size: 73%; font-style: normal; font-weight: normal;">型<spanArial Unicode MS', serif; font-size: 73%; font-style: normal; font-weight: normal;">,<spanArial Unicode MS', serif; font-size: 73%; font-style: normal; font-weight: normal;">再<spanArial Unicode MS', serif; font-size: 73%; font-style: normal; font-weight: normal;">找<spanArial Unicode MS', serif; font-size: 73%; font-style: normal; font-weight: normal;">到<spanArial Unicode MS', serif; font-size: 73%; font-style: normal; font-weight: normal;">赋<spanArial Unicode MS', serif; font-size: 73%; font-style: normal; font-weight: normal;">值<spanArial Unicode MS', serif; font-size: 73%; font-style: normal; font-weight: normal;">的<spanArial Unicode MS', serif; font-size: 73%; font-style: normal; font-weight: normal;">最<spanArial Unicode MS', serif; font-size: 73%; font-style: normal; font-weight: normal;">后<spanArial Unicode MS', serif; font-size: 73%; font-style: normal; font-weight: normal;">实<spanArial Unicode MS', serif; font-size: 73%; font-style: normal; font-weight: normal;">现<spanArial Unicode MS', serif; font-size: 73%; font-style: normal; font-weight: normal;">为zendassigntovariable<spanArial Unicode MS', serif; font-size: 73%; font-style: normal; font-weight: normal;">函<spanArial Unicode MS', serif; font-size: 73%; font-style: normal; font-weight: normal;">数<spanArial Unicode MS', serif; font-size: 73%; font-style: normal; font-weight: normal;">。<spanArial Unicode MS', serif; font-size: 73%; font-style: normal; font-weight: normal;">这<spanArial Unicode MS', serif; font-size: 73%; font-style: normal; font-weight: normal;">在<spanArial Unicode MS', serif; font-size: 73%; font-style: normal; font-weight: normal;">前<spanArial Unicode MS', serif; font-size: 73%; font-style: normal; font-weight: normal;">面<spanArial Unicode MS', serif; font-size: 73%; font-style: normal; font-weight: normal;">的<spanArial Unicode MS', serif; font-size: 73%; font-style: normal; font-weight: normal;">小<spanArial Unicode MS', serif; font-size: 73%; font-style: normal; font-weight: normal;">节<spanArial Unicode MS', serif; font-size: 73%; font-style: normal; font-weight: normal;">中<spanArial Unicode MS', serif; font-size: 73%; font-style: normal; font-weight: normal;">已<spanArial Unicode MS', serif; font-size: 73%; font-style: normal; font-weight: normal;">经<spanArial Unicode MS', serif; font-size: 73%; font-style: normal; font-weight: normal;">详<spanArial Unicode MS', serif; font-size: 73%; font-style: normal; font-weight: normal;">细<spanArial Unicode MS', serif; font-size: 73%; font-style: normal; font-weight: normal;">介<spanArial Unicode MS', serif; font-size: 73%; font-style: normal; font-weight: normal;">绍<spanArial Unicode MS', serif; font-size: 73%; font-style: normal; font-weight: normal;">过<spanArial Unicode MS', serif; font-size: 73%; font-style: normal; font-weight: normal;">了<spanArial Unicode MS', serif; font-size: 73%; font-style: normal; font-weight: normal;">。<spanArial Unicode MS', serif; font-size: 73%; font-style: normal; font-weight: normal;">我<spanArial Unicode MS', serif; font-size: 73%; font-style: normal; font-weight: normal;">们<spanArial Unicode MS', serif; font-size: 73%; font-style: normal; font-weight: normal;">这<spanArial Unicode MS', serif; font-size: 73%; font-style: normal; font-weight: normal;">个<spanArial Unicode MS', serif; font-size: 73%; font-style: normal; font-weight: normal;">例<spanArial Unicode MS', serif; font-size: 73%; font-style: normal; font-weight: normal;">子<spanArial Unicode MS', serif; font-size: 73%; font-style: normal; font-weight: normal;">是<spanArial Unicode MS', serif; font-size: 73%; font-style: normal; font-weight: normal;">很<spanArial Unicode MS', serif; font-size: 73%; font-style: normal; font-weight: normal;">简<spanArial Unicode MS', serif; font-size: 73%; font-style: normal; font-weight: normal;">单<spanArial Unicode MS', serif; font-size: 73%; font-style: normal; font-weight: normal;">的<spanArial Unicode MS', serif; font-size: 73%; font-style: normal; font-weight: normal;">一<spanArial Unicode MS', serif; font-size: 73%; font-style: normal; font-weight: normal;">种<spanArial Unicode MS', serif; font-size: 73%; font-style: normal; font-weight: normal;">赋<spanArial Unicode MS', serif; font-size: 73%; font-style: normal; font-weight: normal;">值<spanArial Unicode MS', serif; font-size: 73%; font-style: normal; font-weight: normal;">,<spanArial Unicode MS', serif; font-size: 73%; font-style: normal; font-weight: normal;">在<spanArial Unicode MS', serif; font-size: 73%; font-style: normal; font-weight: normal;">源<spanArial Unicode MS', serif; font-size: 73%; font-style: normal; font-weight: normal;">码<spanArial Unicode MS', serif; font-size: 73%; font-style: normal; font-weight: normal;">中<spanArial Unicode MS', serif; font-size: 73%; font-style: normal; font-weight: normal;">是<spanArial Unicode MS', serif; font-size: 73%; font-style: normal; font-weight: normal;">直<spanArial Unicode MS', serif; font-size: 73%; font-style: normal; font-weight: normal;">接<spanArial Unicode MS', serif; font-size: 73%; font-style: normal; font-weight: normal;">将
以上就介绍了PHP内核探索:变量类型的转换,包括了方面的内容,希望对PHP教程有兴趣的朋友有所帮助。
内容总结
以上是互联网集市为您收集整理的PHP内核探索:变量类型的转换全部内容,希望文章能够帮你解决PHP内核探索:变量类型的转换所遇到的程序开发问题。
如果觉得互联网集市技术教程内容还不错,欢迎将互联网集市网站推荐给程序员好友。
内容备注
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 gblab@vip.qq.com 举报,一经查实,本站将立刻删除。
内容手机端
来源:【匿名】