Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6597635
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T18:14:03+00:00 2026-05-25T18:14:03+00:00

function foo($a) { $b = …; $c = …; return (both b and c);

  • 0
function foo($a)
{
    $b = ...;
    $c = ...;
    return (both b and c);
}

and so I could get $b value to $first and $c value to $second

I know you can return more than 1 variable by return array($b,$c) but then it should be $var[0] and $var[1] and then I need to type $first = $var[0] and $second = $var[1] and so I’m creating more useless variables

So is it possible to do so without array?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T18:14:04+00:00Added an answer on May 25, 2026 at 6:14 pm

    Fundamentally, functions only have one return value. You could return a class with member variables first and second, or an associative array with keys "first" and "second", but you’ll still only be returning a single object.*

    Alternatively, you could references to $first and $second into your function:

    function foo($a, &$b, &$c)
    {
        $b = ...;
        $c = ...;
    }
    
    foo(42, $first, $second);
    

    I’m not a big fan of this approach, though, because it’s not immediately clear from the call-site that $first and $second are going to be modified.

    * Note that if you return an array, you can always use the short-hand list($first,$second) = foo(42);.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a function returning an array: function foo(){ return array('foo'=>1,'bar'=>2); } Can I
I have a ColdFusion function foo which takes three args, and the second two
Public Function Foo() as String() Dim bar As String = {bar1,bar2,bar3} Return bar End
var foo = function(){}; foo.prototype.value = 5; foo.prototype.addValue = function(){ foo.value = 6; }
for example in PHP class foo{ function foo($name){ //constructor $this->name=$name; } function sayMyName(){ return
1 function foo($i){ 2 return bar($i)*4; 3 function bar($i){ 4 return $i*4; 5 }
I have a function 'foo' and a variable '$foo' referencing it. function foo {
as expected it invokes the function foo the first time, but when i want
function foo() return a, b, c end function bar() return foo() end function process()
var foo = function(){ return 1; }; if (true) { function foo(){ return 2;

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.