include 'Cat.php'; $cat1 = new Cat(); $cat1->setColor("black"); $cat1->setname("Zoe"); $cat1->setBreed("Scottish Fold"); $myCats[] = $cat1; $cat2 = new Cat(); $cat2->setColor("orange"); $cat2->setname("Garfield"); $cat2->setBreed("Persian"); $myCats[] = $cat2; $cat3 = new Cat(); $cat3->setColor("tabby"); $cat3->setname("Fluffy"); $cat3->setBreed("Ragamuffin"); $myCats[] = $cat3; $cont = 0; displayCount($cat1, $cont); // calling the function to count the cats. displayCount($cat2, $cont); displayCount($cat3, $cont); echo "The number of cat that the color is orange is " . $cont; displayCatInfo($cat1); displayCatInfo($cat2); displayCatInfo($cat3); function displayCount($cat, &$cont) { if ($cat->getColor() == 'orange') { //comparison to verify the orange collor $cont++;
<?php include 'Cat.php'; $cat1 = new Cat(); $cat1->setColor("black"); $cat1->setBreed("Calico"); $cat1->setname("Zoe"); $myCats[] = $cat1; $cat2 = new Cat(); $cat2->setColor("orange"); $cat2->setBreed("Siamese"); $cat2->setname("Garfield"); $myCats[] = $cat2; $cat3 = new Cat(); $cat3->setColor("tabby"); $cat3->setBreed("Lion"); $cat3->setname("Fluffy"); $myCats[] = $cat3; displayCatInfo($cat1); displayCatInfo($cat2); displayCatInfo($cat3); echo "The number of cats of color orange is " . countByColor("orange", $myCats); function displayCatInfo($catExample) { echo "Name: " . $catExample->getName(); echo "<br>"; echo "Color: " . $catExample->getColor(); echo "<br>"; echo "Breed: " . $catExample->getBreed(); echo "<br>"; echo "<br>";
include_once 'Cat.php'; $cat1 = new Cat(); $cat1->setColor("black"); $cat1->setname("Zoe"); $cat1->setBreed("Siamese"); $myCats[] = $cat1; $cat2 = new Cat(); $cat2->setColor("orange"); $cat2->setname("Garfield"); $cat2->setBreed("Sphynx"); $myCats[] = $cat2; $cat3 = new Cat(); $cat3->setColor("tabby"); $cat3->setname("Fluffy"); $cat3->setBreed("Ragdoll"); $myCats[] = $cat3; displayInfo($cat1); displayInfo($cat2); displayInfo($cat3); CatListFun($myCats, "orange"); function displayInfo(Cat $n) { echo $n->getName() . " is a " . $n->getColor() . " " . $n->getBreed() . " cat.</br> </br>"; } function CatListFun($catsArray, $selectedColor) { $colorCount = 0; for ($i = 0; $i < count($catsArray); $i++) { if ($catsArray[$i]->getColor() == $selectedColor) { $colorCount++;
include 'Cat.php'; $cat1 = new Cat(); $cat1->setColor("black"); $cat1->setName("Zoe"); $cat1->setBreed("Siamese "); $myCats[] = $cat1; $cat2 = new Cat(); $cat2->setColor("orange"); $cat2->setName("Garfield"); $cat2->setBreed("Tabby "); $myCats[] = $cat2; $cat3 = new Cat(); $cat3->setColor("tabby"); $cat3->setName("Fluffy"); $cat3->setBreed("catType3 "); $myCats[] = $cat3; $count = 0; catCount($myCats, $count); echo "the count for is " . $count . "<br>"; for ($i = 0; $i < 3; $i++) { displayCatInfo($myCats[$i]); } function catCount($cats, &$num) { for ($i = 0; $i < 2; $i++) { if ($cats[$i]->getColor() == "orange") { $num++; } } }
include 'Cat.php'; $cat1 = new Cat(); $cat1->setColor("black"); $cat1->setName("Zoe"); $cat1->setBreed("Burmese"); $myCats[] = $cat1; $cat2 = new Cat(); $cat2->setColor("orange"); $cat2->setName("Garfield"); $cat2->setBreed("LaPerm"); $myCats[] = $cat2; $cat3 = new Cat(); $cat3->setColor("tabby"); $cat3->setName("Fluffy"); $cat3->setBreed("Tabby"); $myCats[] = $cat3; $count = 0; catCount($myCats, $count); echo "The count for is " . $count . "<br>"; for ($i = 0; $i < 3; $i++) { displayCatInfo($myCats[$i]); } function catCount($cats, &$num) { for ($i = 0; $i < 2; $i++) { if ($cats[$i]->getColor() == "black") { $num++; } } }