I’m sure you all know what the “shuffle” function does. What I thought I could make it do was randomize a bunch of echoes I have. Is that possible? Any help would be greatly appreciated. KCCO!
Here’s the code I need tweaked:
[php]
CharactersSupers we've helped locate
<? date_default_timezone_set("America/Los_Angeles"); # set default timezone $imageDir = "images/"; # Comics is a PARENT class - Emily, Jenny, and so forth all are CHILDREN of Comics, meaning: They inherit the properties and methods included inside Comics. # For example: echo $joker->comiccharacters; will print out the $comiccharacters stored in Comics class Comics { const IMAGEDIR = "images/"; public $comiccharacters = "Comics"; } class Spiderman extends Comics { public $name = "Spiderman"; public $location = "New York City"; public $superpower = "his spider-sense, augmented speed and strength and his web shooters."; public $sex = "male"; public $published = "1963-03-01."; public $hero = true; public $asseskicked = 37; public $personscaught = [12,16,19,29,51]; public $powerlevel= '++++++'; public $email = "[email protected]"; # A Constructor is automatically called when PHP is loaded public function __construct() { # set path for imageDir $this->imagePath = parent::IMAGEDIR . "spiderman.jpg"; } } $spiderman = new Spiderman(); class Magneto extends Comics { public $name = "Magneto"; public $location = "New York City."; public $superpower = "power of magnetism."; public $sex = "male"; public $published = "1963-10-15."; public $hero = false; public $asseskicked = 52; public $personscaught = [21,11,21,43,31]; public $powerlevel= '+++++++'; public $email = "[email protected]"; # A Constructor is automatically called when PHP is loaded public function __construct() { # set path for imageDir $this->imagePath = parent::IMAGEDIR . "magneto.jpg"; } } $magneto = new Magneto(); class Nightwing extends Comics { public $name = "Nightwing"; public $location = "Gotham City"; public $superpower = "is his peak physical conditioning, gadgets, and detective skills."; public $sex = "male"; public $published = "1985-01-06"; public $hero = true; public $asseskicked = 76; public $personscaught = [32,41,53,48,63]; public $powerlevel= '++++++'; public $email = "[email protected]"; # A Constructor is automatically called when PHP is loaded public function __construct() { # set path for imageDir $this->imagePath = parent::IMAGEDIR . "nightwing.jpg"; } } $nightwing = new Nightwing(); class GreenArrow extends Comics { public $name = "Green Arrow"; public $location = "Starling City"; public $superpower = "is his peak physical conditioning and accuracy with his gadgets."; public $sex = "male"; public $published = "1941-11-19"; public $hero = true; public $asseskicked = 62; public $personscaught = [17,17,29,31,49]; public $powerlevel= '++++++'; public $email = "[email protected]"; # A Constructor is automatically called when PHP is loaded public function __construct() { # set path for imageDir $this->imagePath = parent::IMAGEDIR . "greenarrow.jpg"; } } $greenArrow = new GreenArrow(); class TheJoker extends Comics { public $name = "The Joker"; public $location = "Gotham City"; public $superpower = "being completely insane and psychotic."; public $sex = "male"; public $published = "1940-04-11"; public $hero = false; public $asseskicked = 112; public $personscaught = [61,79,103,94,52]; public $powerlevel= "++++++++"; public $email = "[email protected]"; # A Constructor is automatically called when PHP is loaded public function __construct() { # set path for imageDir $this->imagePath = parent::IMAGEDIR . "joker.jpg"; } } $thejoker = new TheJoker(); # Create an array containing all the members classes $members = array($spiderman, $magneto, $nightwing, $greenArrow, $thejoker); # Calculate Ages - this cycles through all of the classes, and calculates the age for each band member, and places it in a property named "$age" foreach($members as $obj) { $obj->age = calculateAge($obj->published); } # Display our Jump Menu echo "All Characters Sort by Name Sort by Age (youngest to oldest) Sort by Age (oldest to youngest)
"; # Access the sort value from the url: blah.com/?sort=blam $sort = ''; if (isset($_GET['sort'])) { $sort = $_GET['sort']; } # Let's introduce all our members echo "Heroes and Villains Alike
"; for ($i=0; $i < count($members); $i++) { switch ( $sort ) { # sort=name -- sorts alphabetically by 'name' in the member array case "name" : usort($members, 'sortByName_ascend'); displayProfile($members[$i]); break; case "nameRev" : usort($members, 'sortByName_descend'); displayProfile($members[$i]); break; # sort=ageLoToHi -- sorts alphabetically by 'age' ascending case "ageLoToHi" : usort($members, 'sortClassesByAgeLoHi'); displayProfile($members[$i]); break; # sort=ageHiToLo -- sorts alphabetically by 'age' descending case "ageHiToLo" : usort($members, 'sortClassesByAge_HiLo'); displayProfile($members[$i]); break; # sort=ageHiToLo -- sorts alphabetically by 'age' descending case "asseskicked" : uksort($members, 'sortAsseskicked'); displayProfile($members[$i]); break; # default -- spit out all band members according to their order in the array default : displayProfile($members[$i]); break; } } # This is a custom sorting function that works with usort(). # If you provide usort() with either an array or a set of objects, # it goes through all the items and compares them, and puts them in order # according to the rules below. function sortClassesByAgeLoHi($a, $b) { if ( $a->published == $b->published ) { #return 0; # this makes equivalent aged folks disappear :( return 1; } elseif ( $a->published > $b->published ) { return -1; } else { return 1; } } function sortClassesByAge_HiLo($a, $b) { return sortClassesByAgeLoHi($b, $a); # just reverse the arguments } function sortByName_ascend($a, $b) { if ( $a->name == $b->name ) { #return 0; # this makes equivalent aged folks disappear :( return 1; } elseif ( $a->name > $b->name ) { return 1; } else { return -1; } } function sortByName_descend($a, $b) { return sortByName_ascend($b, $a); # just reverse the arguments } # FUNCTIONS - Store all functions down here - I could also store them in another file function displayProfile($memberClass) { echo "";
# spit out the image of our character
#
echo "imagePath."\" width=200px />
";
#should make it so that when you refresh the page, it randomizes the order of the elements in the array
shuffle($memberProfile);
[b][size=18pt]THE FOLLOWING IS SPECIFICALLY WHAT I WANT TO RANDOMIZE[/size][/b]
# spit out our caption
echo "This is ".$memberClass->name.".
";
//counts the "+" for the power level
echo "He has a power level of ".strlen($memberClass->powerlevel)."
";
echo "He resides in ".$memberClass->location.".
";
echo "He was first published in ".displayBirthdate($memberClass->published).".
";
echo "Making him ".calculateAge($memberClass->published)." years old!
";
//wraps the string after the specified # of characters
echo "His superpower is ".wordwrap($memberClass->superpower,35,"
\n")."
";
echo "And in that time he's kicked the asses of ".$memberClass->asseskicked." people!
";
//finds the average & wraps the string after the specified # of characters
echo "They normally capture their respective enemy ".average($memberClass->personscaught)." times a year.
";
echo "You can reach them at ".$memberClass->email."..