HELP WITH BANNERS ROTATOR SCRIPT

Hi, I have this banners rotator script:

[php]<?php
//randomly shuffle the array keeping the relation between keys and values
function shuffle_me($shuffle_me){
$randomized_keys = array_rand($shuffle_me, count($shuffle_me));
foreach($randomized_keys as $current_key) {
$shuffled_me[$current_key] = $shuffle_me[$current_key];
}
return $shuffled_me;
}
$center_banners=shuffle_me($center_banners);
$center_banners=array_slice($center_banners, 0, 20);

$left_banners=shuffle_me($left_banners);
$right_banners=shuffle_me($right_banners);
?>[/php]

OK, the script runs perfectly at a PHP4 server, but it doesn’t work at my current PHP5 server.

I think that the reason is the change at the array_rand log:
5.2.10 - The resulting array of keys is no longer shuffled.

What exactly do I need to change at the script to work at PHP5? As the script is part of a topsite, it is interrelated with multiple programming pages so the change should be the minimum necessary to work with PHP5.

I have done multiple test without results. Consider that my PHP skills are so low. Please, help me!

Maria

Heyyo->

I think this does what you require.
[php]<?php
$center_banners = Array(‘Thing1’,‘Thing2’,‘Thing3’,‘Thing4’,‘Thing5’,‘Thing6’,‘Thing7’,‘Thing8’,‘Thing9’,‘Thing10’,
‘Thing11’,‘Thing12’,‘Thing13’,‘Thing14’,‘Thing15’,‘Thing16’,‘Thing17’,‘Thing18’,‘Thing19’,‘Thing20’,
‘Thing21’,‘Thing22’,‘Thing23’,‘Thing24’,‘Thing25’,‘Thing26’,‘Thing27’,‘Thing28’,‘Thing29’,‘Thing30’,
‘Thing31’,‘Thing32’,‘Thing33’,‘Thing34’,‘Thing35’,‘Thing36’,‘Thing37’,‘Thing38’,‘Thing39’,‘Thing40’);
//randomly shuffle the array keeping the relation between keys and values
function shuffle_me($shuffle_me){
$top = count($shuffle_me);
$banners = array();
$x = 0;
do{
$randomized_key = array_rand($shuffle_me, 1);
if( preg_match(’/’.$randomized_key.’/’,implode("-",$banners), $matches) == 0) {
$banners[$x] = $shuffle_me[$randomized_key];
}
$x++;
} while(count($banners) < 40) ;
return $banners;
}
print_r($center_banners=array_slice(shuffle_me($center_banners), 0, 20));
?>[/php]

Array ( [0] => Thing3 [1] => Thing28 [2] => Thing34 [3] => Thing27 [4] => Thing15 [5] => Thing12 [6] => Thing24 [7] => Thing37 [8] => Thing7 [9] => Thing12 [10] => Thing39 [11] => Thing23 [12] => Thing26 [13] => Thing23 [14] => Thing26 [15] => Thing17 [16] => Thing34 [17] => Thing19 [18] => Thing12 [19] => Thing37 )
You can take it from there I think?

Hope this helps!

Sponsor our Newsletter | Privacy Policy | Terms of Service