Heim  >  Artikel  >  Backend-Entwicklung  >  php类型转换

php类型转换

WBOY
WBOYOriginal
2016-07-25 08:45:561343Durchsuche

使用类型转换,可以将一个变量的值转换成另一种类型。这种转换与c语言的类型转换是相同的。只需在希望进行类型转换的变量之前的圆括号中插入需要转换的临时数据类型即可。
例如:

  1. $totalqty = 0;
  2. $totalamount = (float)$totalqty;
  3. ?>
复制代码

第二行代码的意思是“取出保存在$totalqty中的变量值,将其解释成一个浮点类型,并且将其保存在$totalamount”中。$totalamount变量将变成浮点类型。而被转换的变量并不会改变其类型,因此$totalqty仍然是整数类型。

php


Stellungnahme:
Der Inhalt dieses Artikels wird freiwillig von Internetnutzern beigesteuert und das Urheberrecht liegt beim ursprünglichen Autor. Diese Website übernimmt keine entsprechende rechtliche Verantwortung. Wenn Sie Inhalte finden, bei denen der Verdacht eines Plagiats oder einer Rechtsverletzung besteht, wenden Sie sich bitte an admin@php.cn