PHP 7年前

PHP类型转换

作者头像 刘宇帅
2488 0

PHP 类型转换一共三种方式

在变量前加圆括号,括号内为目标类型

<?php
$a = (int)\'11\';  // 把\'11\'转化为int型
$b = (float)\'11\'; // 把\'11\'转化为float型

使用intval,floatval,strval函数转换

<?php
$a = intval(\'11\'); // 把\'11\'转化为int型
$b = floatval(\'11\'); // 把\'11\'转化为float型

使用settype函数

<?php
$a = \'11\';
settype($a, \'int\'); // 把\'11\'转化为int型
settype($a, \'float\'); // 把\'11\'转化为float型
作者头像

刘宇帅

非著名程序员,全栈开发工程师,长期专注系统开发与架构设计。

提示

功能待开通!


暂无评论~

相关文章

Phalcon框架介绍

前言 专门写这一篇文章来介绍 Phalcon 首先是因为本站的系统就是基于 Phalcon搭建的,第二就是先后两次接触 Phacon 体会差别比较大,第三就是就我现在觉得 Phalcon 其实是挺好的一框架怎么就没火起来呢,很郁闷,所以写这篇文章表达下自己的看法。 Phalcon框架整体介绍 Phalcon 是一个基于 MVC 的 PHP 框架,因为其最终的交付形式是 C 语言编译成的 PHP 扩展,所以其比大多数 PHP 开发的框架速度都要快。Phalcon 提供了对主要关系型数据库、NoSql、缓存、日志、模板引擎、表单构建器、国际语言支持等各类功能的支持。想使用 PHP 构建高性能 RE

centos7 php72 phalcon环境安装

1.配置软件源 yum install epel-release rpm -ivh https://rpms.remirepo.net/enterprise/remi-release-7.rpm rpm --import /etc/pki/rpm-gpg/RPM-GPG-KEY-remi 2.启用remi源 /etc/yum.repos.d/remi.repo,在[remi]下边的enabled=0改为enabled=1 3.修改/etc/yum.repos.d/remi-php72.repo enabled=1即可。 4.安装php72 phalcon nginx及相关扩展 yum inst

你不知道的PHP

array的key可以是Integer、string类型。其他类型的key会进行转化 包含有合法整型值的字符串会被转换为整型。例如键名 &quot;8&quot; 实际会被储存为 8。但是 &quot;08&quot; 则不会强制转换,因为其不是一个合法的十进制数值。 浮点数也会被转换为整型,意味着其小数部分会被舍去。例如键名 8.7 实际会被储存为 8。 布尔值也会被转换成整型。即键名 true 实际会被储存为 1 而键名 false 会被储存为 0。 Null 会被转换为空字符串,即键名 null 实际会被储存为 &quot;&quot;。 数组和对象不能被用为键名。坚持这么做会导致警告

PHP数组合并

PHP数组合并有两种方式 数组运算符操作:+ The + operator returns the right-hand array appended to the left-hand array; for keys that exist in both arrays, the elements from the left-hand array will be used, and the matching elements from the right-hand array will be ignored. 两个数组相加结果为把第二个数组链接在第一个数组之后,如果两个数组有key重复的就

PHP官方属性访问错误示例

PHP 可变属性的官方中文版Exampl1例子是错误的 官方地址 Example 1 &lt;?php class foo { var $bar = 'I am bar.'; var $arr = array('I am A.', 'I am B.', 'I am C.'); var $r = 'I am r.'; } $foo = new foo(); $bar = 'bar'; $baz = array('foo', 'bar', 'baz', 'quux'); echo $foo-&gt;$bar . "\n"; echo $foo-&gt;$baz[1]