S
S
sgn_crazushot2018-02-28 11:53:07
PHP
sgn_crazushot, 2018-02-28 11:53:07

How to make the numbers in a certain place on the machine be replaced by words?

Hello!
How to implement such a thing:
I have a page - a profile, information from the MySQL database is displayed on it.
There is one stanza - this stanza is the user's rank, info is displayed there in numbers.
Is it possible to implement such a thing that these numbers in the final version on the site page will change into words?
Suppose it displays the number "4" there, and on the page it will show "admin"?

Answer the question

In order to leave comments, you need to log in

3 answer(s)
S
sgn_crazushot, 2018-02-28
@sgn_crazushot

Found the solution in the code:
$user_progile[rank] = str_replace("1","Player",$user_progile[rank]);
$user_progile[rank] = str_replace("2","Admin",$user_progile[rank]);
Thanks to everyone who wanted to help

D
Dmitry Kuznetsov, 2018-02-28
@dima9595

Purely conditions. if, else, elseif... It is also possible through switch case

D
DarkByte2015, 2018-02-28
@DarkByte2015

A more correct and shorter version is map.

$matching = [ 1 => 'admin', 2 => 'editor', 3 => 'user' ];
echo $matching[$role];

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question