Get the App
SLTechnology News&Howtos  ›  Internet Technology  › 

How to use return statements in php

Shulou Source: shulou.com Published: 2022-05-31 10:56:30 10月03日 Update

This article mainly introduces the relevant knowledge of "how to use return sentences in php". The editor shows you the operation process through an actual case. The operation method is simple, fast and practical. I hope this article "how to use return sentences in php" can help you solve the problem.

1. Description

(1) return exits from the current method, returns to the statement of the calling method, and continues execution.

(2) return returns a value to the statement that calls the method, and the data type of the return value must be the same as the type of the return value in the method declaration.

(3) return can also be followed by no parameters, no parameters is to return empty, in fact, the main purpose is to interrupt the function execution and return to the calling function.

two。 Attention to use

Return parameters. It is recommended that you do not add parentheses. Because return is a language structure rather than a function, its arguments usually do not use parentheses, and in fact they should not be used, which reduces the burden on PHP.

When no parameter is returned, it must be returned without parentheses. Because when no parameter is returned, NULL is returned by default. Parsing errors can occur if you call return with parentheses but no arguments.

3. Example

In the method of jumping out of the loop, we have learned the common use, this article needs to introduce a language structure return. When we learn about other programming, generally speaking, return is used as a function, but if you put it in a php statement, you can't use the function.

This is the end of the introduction to "how to use return statements in php". Thank you for reading. If you want to know more about the industry, you can follow the industry information channel. The editor will update different knowledge points for you every day.

Tags: Parameters statements methods functions parentheses knowledge no actually that is types structures industries languages loops different practical consistent generally speaking code content Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno MariaDB Linux Shulou Information vpn Xiaomi