search
Homephp教程php手册实例详解php中的return语句

这篇文章主要介绍了php中的return语句 ,有一定的参考价值,感兴趣的朋友可以看看, 希望对你哟所帮助!

一个函数中可以有return语句,也可以没有。什么时候需要呢?就是当你想接收函数的执行结果的时候,你需要一个return 语句。

函数执行完return语句之后,return语句后面的代码是永远不会得到执行的。

PHP中的return一般情况下只能通过return获得一个返回值,如果想获得多个返回值,可以返回一个数组。

1 <?php2 3 function sayHello($a,$b)4 {5     return $a;6     return $b;7 }8 9 ?>

想通过两个return语句获得两个返回值,但结果是只能返回a的值。

下图展示了一个用return返回数组的例子。

sayHello函数通过return返回一个数组,用变量temp来接收这个数组,再通过foreach循环输出返回的值。

【相关教程推荐】

1. php编程从入门到精通全套视频教程 

2. php从入门到精通  

3. bootstrap教程 

Statement
This article is reproduced at:博客园. If there is any infringement, please contact admin@php.cn delete

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 Article

Hot Tools

Safe Exam Browser

Safe Exam Browser

Safe Exam Browser is a secure browser environment for taking online exams securely. This software turns any computer into a secure workstation. It controls access to any utility and prevents students from using unauthorized resources.

VSCode Windows 64-bit Download

VSCode Windows 64-bit Download

A free and powerful IDE editor launched by Microsoft

MantisBT

MantisBT

Mantis is an easy-to-deploy web-based defect tracking tool designed to aid in product defect tracking. It requires PHP, MySQL and a web server. Check out our demo and hosting services.

SAP NetWeaver Server Adapter for Eclipse

SAP NetWeaver Server Adapter for Eclipse

Integrate Eclipse with SAP NetWeaver application server.

SecLists

SecLists

SecLists is the ultimate security tester's companion. It is a collection of various types of lists that are frequently used during security assessments, all in one place. SecLists helps make security testing more efficient and productive by conveniently providing all the lists a security tester might need. List types include usernames, passwords, URLs, fuzzing payloads, sensitive data patterns, web shells, and more. The tester can simply pull this repository onto a new test machine and he will have access to every type of list he needs.