マテリアルカラーをランダムに3色取得 / 重複も許容

概要

 閲覧数:1633  投稿日:2018-02-26  更新日:2018-02-26  

マテリアルカラー全19色を、予め配列定義
・ランダムに3色取得
※重複も許容


コード

$materialColor = ['f44336','E91E63','9C27B0','673AB7','3F51B5','2196F3','03A9F4','00BCD4','009688','009688','4CAF50','8BC34A','FFEB3B','FFC107','FF9800','FF5722','795548','9E9E9E','607D8B'];
for ($i=0;$i<=2;$i++) {
  $key = array_rand($materialColor);
  $randColor[] = $materialColor[$key];
}
print_r($randColor);



結果

Array
(
    [0] => 9C27B0
    [1] => E91E63
    [2] => E91E63
)



タグ


array_rand 





マテリアルカラーをランダムに3色取得 / 重複なし