I’m trying to replace the letters with numbers and then add them up

Asked

Viewed 92 times

-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";
  • Ever tried to make a if? And what would be the variable $result that is not defined? And why did you make a print in the middle of <select>?

1 answer

0

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

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

the arguments are:

input string, number of characters, value to be used 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 ]] )

https://secure.php.net/manual/en/function.str-pad.php

  • boooa my boom! that’s right, vlww!

Browser other questions tagged

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