Create multiple PHP variables in the same function

0

I need a very simple function, but I could not find anything related in my searches.

I need a function where I can insert items, and then print these items on another page.

Ex:

    function funcaoExibe() {
 $var = 'none1';
 $var = 'email2';
 $var = 'telefone3';
    echo $var;
}

I created the function, I need to display all the values of the variables inserted inside the function, something like this:

   <?= funcaoExibe(); ?>

No resultado aparece somente:

telefone3

I need to display the 3, one on each line.

Any ideas how I can do it?

    
asked by anonymous 12.07.2018 / 15:25

2 answers

1

You can mount the html in a php file and display it in another way.

// file.php

    <?php
       function ProcessarInformacao($nome, $email, $telefone) {
          $html  = "<div>";
          $html .= "<p>Nome: ".$nome."</p>";
          $html .= "<p>Email: ".$email."</p>";
          $html .= "<p>Telefone: ".$telefone."</p>";
          $html  = "</div>";

          return $html;
       }
    ?>

// display_result.php

echo ProcessarInformacao('Nome Teste', '[email protected]', '(17) 3030-4040');
    
12.07.2018 / 15:39
1

You can make the function return an array (array) In the a.php file you enter the information:

a.php

<?php
function funcaoExibe( $nome, $email, $telefone ) {
  $retorno = array(
    'nome'  => $nome,
    'email' => $email,
    'fone'  => $telefone
  );    
return $retorno;    
} 
?>

Here you choose what you want to display

<?php
  $var = funcaoExibe('Carlos', '[email protected]', '(12)3454-6555');
  echo  $var['nome']."<br>" ;
  echo  $var['email']."<br>" ;
  echo  $var['fone']."<br>" ;
?>
    
12.07.2018 / 15:58