I'm working on a script which rotates multiple slogans from an array. It picks a random array item and displays it, like so:
function sloganrotator_sc() {
global $sloganrotator_options;
$sentences = $sloganrotator_options['slogans'];
$array = explode("
", $sentences);
if (count($array) > 1) {
$randomize = array_rand($array);
$result = $array[$randomize];
return $result;
} else {
return $sloganrotator_options['slogans'];
}
}
add_shortcode( 'slogan-rotator', 'sloganrotator_sc' );
What I'm trying to archieve is to check if the value on page 1 is not the same as on page 2.
For example: Before the page refresh, the value was 'Hello', after the refresh the value is 'Dogs'. I want to check if it doesn't pick the same item twice.
Something like this:
if($array[$randomize] == $result) {
return 'Hold on, this one has already been shown!';
}
Sorry for my bad explanation, it's hard to explain..