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

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

<?php
  function retrieve_user_profile() {
   user[] = "Jason";
   user[] = "jb51.net";
   user[] = "English";
   returnuser;
  }
  list(name,email,language) = retrieve_user_profile();
  echo "Name:name, email: email, preferred language:language";
?>
prolove 的头像

发表回复

  • b853

  • 9388

  • bc41

  • 0128

  • e36e

Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.

Insert the contact form shortcode with the additional CSS class- "bloghoot-newsletter-section"

By signing up, you agree to the our terms and our Privacy Policy agreement.