str_pad returning empty value

Asked

Viewed 34 times

0

created a function with str_pad for my site, but it is returning me a blank value someone could give me a help?

    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;

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;
  • Hello friend... perfect was that very... rsrs

  • 1

    Hello, good! If you used the answer, select it as the correct answer so that other people who had the same problem see how to solve. Thank you.

  • 1

    @guastallaigor one day it will answer as right. rs

Browser other questions tagged

You are not signed in. Login or sign up in order to post.