Jump to content

Return multi vars does not work :(


Miko

Recommended Posts

Hi,

 

I'm testing a function that should return an array containing 2 or more vars.

But seems that I did something wrong because when I echo the function it gives me 'Array'

 

<?php

$test1 = 'test1';
$test2 = 'test2';

function Return_Test($test1,$test2){

	switch($test1){

		case 'test1';
		$test1 = 'testbla';
		break;

		case 'test2';
		$test2 = 'testbla bla';
		break;

	}

	switch($test2){

		case 'test2';
		$test2 = 'yipie';
		break;

		case 'test2';
		$test2 = 'youhou';
		break;

	}

	return array($test1,$test2);

}

?>

<html>
<head>
	<title>Hello</title>
</head>
<body>

<table>
	<tr>
		<td><?php echo Return_Test($test1,$test2); ?></td>
	</tr>
</table>

</body>
</html>

 

What did I do wrong here?

Link to comment
https://forums.phpfreaks.com/topic/167523-return-multi-vars-does-not-work/
Share on other sites

Hi, thanks for your answer.

I've tested it with a loop:

 

<?php
   
   $test1 = 'test1';
   $test2 = 'test2';
   
   function Return_Test($test1,$test2){
      
      switch($test1){
      
         case 'test1';
         $test1 = 'testbla';
         break;
      
      }
      
      switch($test2){
         
         case 'test2';
         $test2 = 'yipie';
         break;
         
      }
      
      return array($test1,$test2);
      
   }

$return = Return_Test($test1,$test2);
      
?>

<html>
   <head>
      <title>Hello</title>
   </head>
<body>
   
   <table>
      <tr>
         <td><?php foreach($return as $key => $value){echo $value."<br />"} ?></td>
      </tr>
   </table>
   
</body>
</html>

 

So this works great! :)

 

But now I need to build this into another php file (functions.php) and in my index.php I should echo or print out the foreach loop, but without coding the loop in the index.php, normally I could do this with Smarty, but this unfortunally not an option :(

 

is there another way?

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.