Home > Backend Development > PHP Tutorial > php中实现可以返回多个值的函数实例

php中实现可以返回多个值的函数实例

PHPz
Release: 2018-10-10 14:51:57
Original
1231 people have browsed it

本文实例讲述了php中实现可以返回多个值的函数用法。分享给大家供大家参考。具体分析如下:

在python和golang中都有一个函数同时返回多个值的方法,其实php也可以,但相比python和golang要稍微麻烦一点,下面是一个简单的演示范例,这里用到了list函数

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

希望本文所述对大家的php程序设计有所帮助。

更多相关教程请访问 php编程从入门到精通全套视频教程

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