WebToTell - Best Forum Site for PHP Developer |  Best PHP online Community | PHP Applications Discussion Forum
Return Multiple Values From A Function in PHP - Printable Version

+- WebToTell - Best Forum Site for PHP Developer | Best PHP online Community | PHP Applications Discussion Forum (https://webtotell.com)
+-- Forum: PHP for beginners and advance users.PHP Code samples, applications. (https://webtotell.com/Forum-PHP-for-beginners-and-advance-users-PHP-Code-samples-applications)
+--- Forum: Simple PHP Forum - Discussion Forum in PHP (https://webtotell.com/Forum-Simple-PHP-Forum-Discussion-Forum-in-PHP)
+---- Forum: PHP Functions (https://webtotell.com/Forum-PHP-Functions)
+---- Thread: Return Multiple Values From A Function in PHP (/Thread-Return-Multiple-Values-From-A-Function-in-PHP)



Return Multiple Values From A Function in PHP - omer - 06-11-2019

A function can not return multiple values, but similar results can be obtained by returning an array. Solution is very simple and straight forward.
PHP Code:
PHP Code:
<?php
 
function returnMultipleValues(){
 
$result = array() ;

 
$result['first'] = "multiple value 1" ;
 
$result['second']= "multiple value 2" ;
 return 
$result 
}

$thisIsMultiple returnMultipleValues() ;
echo 
$thisIsMultiple['first'] ."<br>" ;
echo 
$thisIsMultiple['second'] ."<br>" ;

?>