Home > php教程 > php手册 > body text

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

WBOY
Release: 2016-06-13 09:10:50
Original
1141 people have browsed it

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

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

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

<&#63;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";
&#63;>
Copy after login

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

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 Recommendations
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!