str_pad returning empty value

0

I created a function with str_pad for my site, but it is returning a blank value to me, could anyone help me?

    function ret($valor, $tamanho, $orienta){
        if($orienta == 0){
            str_pad($valor, $tamanho, "0", STR_PAD_LEFT);
        }
        else{
            str_pad($valor, $tamanho, " ", STR_PAD_RIGHT);
        }
$teste = ret("37250468", 14, 0);
echo $teste;
    
asked by anonymous 28.04.2018 / 23:26

1 answer

2

Try the code below, I think you just missed you return the values:

    <?php

    function ret($valor, $tamanho, $orienta) {
      if ($orienta == 0){
          return str_pad($valor, $tamanho, "0", STR_PAD_LEFT);
      }
      else {
          return str_pad($valor, $tamanho, " ", STR_PAD_RIGHT);
      }
    }

    $teste = ret("37250468", 14, 0);
    echo $teste;
    
28.04.2018 / 23:38