$tags_key = array_rand($tags, 5); shuffle($tags_key); foreach($tags_key as $key) { echo '' . $tags[$key] . ''; }