I am trying to replace the letters with numbers and then add them [duplicate]

-2
 $nome = "Johnny Henrique da Silva";
$vogais = array('A','E','I','O','U');
$subCarVogais = array('a' => '1','e' => '5','i' => '1','o' => '7','u' => '6');

function funSomaVetor($v) { 
  for ($i=0; $i < sizeof($v); $i++) { 
    $soma = $soma + $v[$i]; } return $soma; 
  }

$resultado = funSomaVetor($subCarVogais); echo "Resultado $resultado";
    
asked by anonymous 29.11.2018 / 19:43

1 answer

0

With str_pad you can fill a string with the values passed until you reach the desired size:

str_pad($input, 2, "0", STR_PAD_LEFT); 

the arguments are:

input string, number of characters, value to fill, fill direction ( STR_PAD_RIGHT , STR_PAD_LEFT , STR_PAD_BOTH ),

  

string str_pad (string $ input, int $ pad_length [ string $ pad_string   [ int $ pad_type]])

     

link

    
29.11.2018 / 19:49