Show values in an array according to a variable

Asked

Viewed 30 times

1

I have a variable that stores a name:

$nome = 'André Ramos';

I have a array that displays all letters:

$letras = array (

            'A' => 1,
            'B' => 2,
            'C' => 3,
            'D' => 4,
            'F' => 8,
            'G' => 3,
            'H' => 5,
            'I' => 1,
            'J' => 1,
            'K' => 2,
            'L' => 3,
            'M' => 4,
            'N' => 5,
            'O' => 7,
            'P' => 8,
            'Q' => 1,
            'R' => 2,
            'S' => 3,
            'T' => 4,
            'U' => 6,
            'V' => 6,
            'X' => 6,
            'W' => 6,
            'Y' => 1,
            'Z' => 7,
            'Á' => 5,
            'É' => 4,
            'Í' => 8,
            'Ó' => 6,
            'Ú' => 3,
            'Ã' => 7,
            'Ñ' => 2

);

When you enter the name in the variable $nome I need the array $letras check each character and display its value. You need to display the value of accentuated letters as well.

For example:

$nome: 'André';

array (size=5)
  0 => int 1
  1 => int 5
  2 => int 4
  3 => int 2
  4 => int 4

Can someone help me ?

  • Is there any connection with that question or that question? It seems to be exactly the same question, only from another user\(ツ)

  • Same question. But I haven’t gotten an answer yet and can’t ask the other user.

  • Nor edit the question?

  • Edited question: link

  • SOLUTION: $characters = str_split(utf8_decode($name)); $numbers = array_map( Function($character) use ($letters) { $key = utf8_encode(strtoupper($character)); Return isset($letters[$key]) ? $letters[$key] : "?"; }, $characters); $nameNumeros = implode($numbers); echo $nameNumeros;

No answers

Browser other questions tagged

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