php function returns instance of multiple values

*文
Release: 2023-03-18 13:46:02
Original
8406 people have browsed it

How does a php function return multiple values? This article mainly introduces the implementation of functions in PHP that can return multiple values, and analyzes the techniques of PHP using arrays to return multiple values. I hope to be helpful.


In python and golang, there is a method for a function to return multiple values ​​​​at the same time. In fact, php can also do it, but it is a little more troublesome than python and golang. The following is A simple demonstration example, the list function is used here


<?php
  function retrieve_user_profile() {
   $user[] = "Jason";
   $user[] = "php.cn";
   $user[] = "English";
   return $user;
  }
  list($name,$email,$language) = retrieve_user_profile();
  echo "Name: $name, email: $email, preferred language: $language";
?>
Copy after login

Related recommendations:

PHP function Note

Introduction to PHP function syntax 1_PHP tutorial

Simple summary of PHP function learning _PHP Tutorial

The above is the detailed content of php function returns instance of multiple values. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!