Home Backend Development PHP Tutorial Variable type PHP judgment variable type implementation code

Variable type PHP judgment variable type implementation code

Jul 29, 2016 am 08:41 AM
Variable type

PHP includes several functions that can determine the type of variables, such as: gettype(), is_array(), is_float(), is_int(), is_object() and is_string().

Copy code The code is as follows:


$s = "this is a string";
$i = 9;
$arr = array(2,4,6);
is_string ($s); //Returns TRUE, indicating that $s is a string variable
is_string($i); //Returns FALSE, indicating that $i is not a string variable
is_array($arr); //Returns TRUE, Indicates that $arr is an array
is_array($s); //returns FALSE, indicating that $s is not an array
$str = "this is a string";
$int = 9;
$bool = FALSE;
echo " The type of $str is: ".gettype($str);
echo "
";
echo "
";
echo "The type of $int is: ".gettype($ int);
echo "
";
echo "
";
echo "The type of $bool is:".gettype($bool);
?>

The above introduces the implementation code of variable type in PHP to determine variable type, including the content of variable type. I hope it will be helpful to friends who are interested in PHP tutorials.

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
2 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Repo: How To Revive Teammates
4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Hello Kitty Island Adventure: How To Get Giant Seeds
4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

How to solve Python's variable undefined error? How to solve Python's variable undefined error? Jun 24, 2023 pm 10:12 PM

Python is a high-level programming language whose ease of use and popularity make it the language of choice for many programmers. Like other languages, Python also has some common types of errors, such as variable undefined errors. When we use an undefined variable in Python, the program throws an exception called "NameError". This kind of error usually occurs in the following situations: Spelling errors: It may be that the variable name is spelled incorrectly, resulting in an undefined variable. We need to check carefully.

What are the java variable types? What are the java variable types? Jan 16, 2024 pm 04:45 PM

Java variable types include: 1. Integer variable; 2. Floating point variable; 3. Character variable; 4. Boolean variable; 5. Reference type variable. Detailed introduction: 1. Integer variables, used to store integers, including positive numbers, negative numbers and zero; 2. Floating point variables, used to store decimals and floating point numbers; 3. Character variables, used to store character data, Java The character variable type in is char, which occupies 16 bits of storage space and can store a 16-bit Unicode character; 4. Boolean variables are used to store Boolean values, such as true or false, etc.

How to use variables in PHP How to use variables in PHP May 20, 2023 pm 02:33 PM

PHP is a very popular web development language that allows developers to create dynamic web applications on the server side. In PHP, a variable is a basic data structure used to store values ​​and data. This article will introduce how to use variables in PHP. Basic Syntax of Variables The syntax for declaring variables in PHP is very simple. Variable names begin with a dollar sign ($), followed by the variable name. Variable names can be a combination of letters, numbers, or underscores, but they must begin with a letter or an underscore. For example, the following code declares a name

The use of data types in PHP The use of data types in PHP May 25, 2023 am 08:52 AM

Data types in PHP are a very important part of programming. In PHP programming, there are various data types that can be used to store different types of values, including numbers, strings, Boolean values, arrays, objects, and null values. Understanding and correctly using these data types is critical to developing efficient and reliable PHP applications. The following are some common PHP data types and their usage: Numbers: PHP uses numbers to store integers and floating point numbers, such as 1, 1.2, etc. Can use math

Automatic conversion and expansion of variable types in PHP Automatic conversion and expansion of variable types in PHP Sep 13, 2023 am 08:19 AM

PHP is a powerful programming language that supports a variety of variable types, including integers, floating point numbers, strings, Boolean values, etc. In PHP, automatic conversion of variable types is a very important feature. This article will introduce in detail the automatic conversion and expansion of variable types in PHP, and provide specific code examples. First, let's take a look at automatic conversion of variable types in PHP. When PHP performs certain operations, if variables of different types are involved, it will automatically convert the type of one variable to the type of the other variable.

How to declare the types of parameters of C++ functions? How to declare the types of parameters of C++ functions? Apr 19, 2024 pm 12:39 PM

Function parameter type declaration is required in C++ and defines the data type of the value passed to the function. Common type qualifiers include const, &, and *, which are used to specify whether the parameter is a constant, reference, or pointer. Correctly declaring parameter types ensures data type consistency, prevents errors, and improves readability.

What are the types of variables in PHP7.0? What are the types of variables in PHP7.0? Jun 01, 2023 am 09:12 AM

PHP7.0 is a widely used scripting language in the field of modern web application development, and it continues to grow with continuous updates and improvements. Variables are fundamental in the PHP language. They represent containers for storing data in an application. In this article, we will introduce the variable types in PHP7.0 so that you can better understand the programming functions of PHP7.0. Variable types in PHP7.0: Integer: Integer variables are used to store integers, which can be positive, negative, or zero. Integer variables can use ten

A deep dive into variable types in Java: a detailed explanation of different variable types A deep dive into variable types in Java: a detailed explanation of different variable types Feb 18, 2024 pm 05:28 PM

Java is an object-oriented programming language, and one of its strengths is its flexible variable type system. In Java, a variable type determines the type of data it can store and the operations it can perform. This article will analyze in detail various commonly used variable types in Java, including basic data types and reference data types. 1. Basic data types: Integer: Java’s integer data types include byte, short, int and long, which occupy 1 byte, 2 bytes, 4 bytes and 8 bytes of memory space respectively.

See all articles