Skip to content Skip to sidebar Skip to footer

Php: Load One Of 3 Html Snippets Randomly

probably a simple thing but I can't think of an easy and good solution … I want to load one of three videos randomly on page load …

Solution 2:

<?php$videos = ['cloud', 'bath', 'train'];
    $max    = count($videos);       // gives 3 $i      = rand(0, $max - 1);    // we need 0 to 2 $exts   = ['mp4','oog','webm']; // oog is not needed?><videoloopautoplayclass="StretchtoFit"><?phpforeach($extsas$ext):
        echo'<source src="assets/videos/'. $videos[$i].$ext. '" type="video/'. $ext .'">';
    endforeach; 
?></video>

Post a Comment for "Php: Load One Of 3 Html Snippets Randomly"