Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5

Return Multiple Values From A Function in PHP
#1

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

?>
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)