Solved

Is it possible to return 2 things in PHP?

Posted on 2008-06-16
2
218 Views
Last Modified: 2008-06-16
Is it possible to return 2 things from a function in PHP?
0
Comment
Question by:mawingho
2 Comments
 
LVL 49

Accepted Solution

by:
Roonaan earned 500 total points
ID: 21791431
You would return an array:
function doMath($value1, $value2) {

  return array($value1+$value2, $value1 * $value2);
}

$return = doMath(1, 2);
$added = $return[0];
$multiplied = $return[1];

Or use:

list($added, $multiplied) = doMath(1,2);

Kind regards

-r-
0
 

Author Comment

by:mawingho
ID: 21791454
i see
0

Featured Post

Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article discusses four methods for overlaying images in a container on a web page
Introduction This article is intended for those who are new to PHP error handling (https://www.experts-exchange.com/articles/11769/And-by-the-way-I-am-New-to-PHP.html).  It addresses one of the most common problems that plague beginning PHP develop…
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.

776 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question