WebToTell
Return Multiple Values From A Function in PHP - Printable Version

+- WebToTell (https://www.webtotell.com)
+-- Forum: PHP for beginners and advance users.PHP Code samples, applications. (https://www.webtotell.com/Forum-PHP-for-beginners-and-advance-users-PHP-Code-samples-applications)
+--- Forum: PHP (https://www.webtotell.com/Forum-PHP)
+---- Forum: PHP Functions (https://www.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 - turgam - 03-27-2019

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
 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>" ;

?>