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

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

PHPz
PHPzOriginal
2016-05-16 20:19:461209browse

本文实例讲述了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";
?>

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

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

Statement:
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