Home Backend Development PHP Problem What is the difference between print_r and var_dump

What is the difference between print_r and var_dump

Jun 29, 2020 pm 03:44 PM
var_dump

The difference between print_r and var_dump is: the print_r function is used to print the content and structure of the array, and display the keys and elements according to a certain format; while the function var_dump is used to determine the type or length of a variable and output the value of the variable , and return the data type.

What is the difference between print_r and var_dump

Introduction to the difference between print_r and var_dump:

print_r() function

This function can Prints the value of a complex type variable. Use print_r() to print out the entire array content and structure, and display the keys and elements in a certain format. In fact, it's not just for printing, but for printing easy-to-understand information about variables.

For example: print array $age

<?php
    $age=array(18,20,24);
    print_r($age);
?>

//运行结果:Array ( [0] => 18 [1] => 20 [2] => 24 )
Copy after login

var_dump() function

This function determines the type and length of a variable and outputs The value of the variable. If the variable has a value, the value of the variable is output and the data type is returned.

This function displays structural information about one or more expressions, including the expression's type and value. Arrays will expand values ​​recursively, showing their structure through indentation.

For example:

<?php
    $age=array(18,20,24);
    var_dump($age);
?>

//运行结果:array(3) { [0]=> int(18) [1]=> int(20) [2]=> int(24) }
Copy after login

If you want to know more related content, please pay attention to php Chinese website.

The above is the detailed content of What is the difference between print_r and var_dump. For more information, please follow other related articles on the PHP Chinese website!

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

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

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)