.
.
...2017-01-16 17:53:35
Habr
..., 2017-01-16 17:53:35

Random avatar color?

Hello everyone, I'm very interested in the method that Habrahabr uses. Namely, how do they implement the random color of standard avatars for users?
prntscr.com/dwc93m
prntscr.com/dwc99a
looked at the source code

<span class="user-pic_default user-pic_default_47 user-pic_blue"></span>

<span class="user-pic_default user-pic_default_47 user-pic_lilac"></span>

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alexey Bumburum, 2017-01-16
@Boomburum

$colors = ['blue', 'pink', 'lilac', 'green'];
$color=$colors[ $userId%count($colors) ]

:)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question