PHP is_scalar() 函数

PHP 教程 · 2019-01-31 20:12:37

is_resource() 函数用于检测变量是否是一个标量。

标量变量是指那些包含了 integer、float、string 或 boolean 的变量,而 array、object 和 resource 则不是标量。

PHP 4 >= 4.0.5, PHP 5, PHP 7

语法

bool is_resource ( mixed $var )

参数说明:

  • $var:要检测的变量。

返回值

如果指定变量是标量返回 TRUE,否则返回 FALSE。

实例

实例

<?php function show_var($var) { if (is_scalar($var)) { echo $var; } else { var_dump($var); } } $pi = 3.1416; $sites = array("Codercto", "Google", "Facebook"); show_var($pi); echo PHP_EOL; show_var($sites) ?>

输出结果为:

3.1416
array(3) {
  [0]=>
  string(6) "Codercto"
  [1]=>
  string(6) "Google"
  [2]=>
  string(8) "Facebook"
}

点击查看所有 PHP 教程 文章: https://www.codercto.com/courses/l/5.html

查看所有标签

An Introduction to Genetic Algorithms

An Introduction to Genetic Algorithms

Melanie Mitchell / MIT Press / 1998-2-6 / USD 45.00

Genetic algorithms have been used in science and engineering as adaptive algorithms for solving practical problems and as computational models of natural evolutionary systems. This brief, accessible i......一起来看看 《An Introduction to Genetic Algorithms》 这本书的介绍吧!

CSS 压缩/解压工具
CSS 压缩/解压工具

在线压缩/解压 CSS 代码

URL 编码/解码
URL 编码/解码

URL 编码/解码

MD5 加密
MD5 加密

MD5 加密工具