vinbarbre Posted December 9, 2013 Share Posted December 9, 2013 I'm near completing my second php course . I've added my final just below. I'm sure you all know what the "array_merge" function does. I've added the array_merge to a new echo, so that I can merge two arrays together. I wanted to combine ($company->name, $company->department) together. <html> <head> <title>PHP</title> <link rel="stylesheet" href="assets/css/bootstrap.css" media="screen"> <link rel="stylesheet" href="assets/css/bootstrap-responsive.css" media="screen"> <link rel="stylesheet" href="assets/css/normalize.css" type="text/css" media="screen"> <link rel="stylesheet" href="assets/css/style.css" media="screen"> </head> <body> <div class="navbar"> <div class="navbar-inner"> <a class="brand" href="#">Week 9</a> <ul class="nav"> <li class="active"><a href="clients.php">Clients</a></li> <li><a href="potential clients.php">Potential Clients</a></li> <li><a href="previousclients.php">Pervious Clients</a></li> </ul> </div> </div><!-- END of navbar--> <div align="center"> <h1>CLients</h1> <? date_default_timezone_set("America/Los_Angeles"); # set default timezone $imageDir = ".../assets/images"; class Clients { const IMAGEDIR = "images/"; public $clients = "Clients"; } /** * */ class Nike extends Clients { public $category = "sporting goods"; public $name = "Nike"; public $department = "Multi Media Devision"; public $yearsWorked = 9; public $jobPerYear = 10; public $fullTimeEmployment = false; public $freelance= true; public $annualBudget= 100000; public $founding= "1999-10-27"; public $visitsBeforeHire= 12000; public $visitsAfterHire= 23000; public $expenses= 100 ; public $income= 500 ; public $activelyWorking= true ; # A Constructor is automatically called when PHP is loaded public function __construct() { # set path for imageDir $this->imagePath = parent::IMAGEDIR . "nike.gif"; } } $nike = new Nike(); class CoffeePress extends Clients { public $category = "coffee"; public $name = "Coffee Press"; public $department = "UI/UX Devision"; public $yearsWorked = 5; public $jobPerYear = 10; public $fullTimeEmployment = false; public $freelance= true; public $annualBudget= 50; public $founding= "11992-05-12"; public $visitsBeforeHire= 12000; public $visitsAfterHire= 23000; public $expenses= 1700 ; public $income= 2500 ; public $activelyWorking= true; # A Constructor is automatically called when PHP is loaded public function __construct() { # set path for imageDir $this->imagePath = parent::IMAGEDIR . "coffeepress.jpg"; } } $coffeePress = new CoffeePress(); class BarrettsFruitProduce extends Clients { public $category = "fruit delivery"; public $name = "Barrett's Fruit Produce"; public $department = "Branding / Marketing"; public $yearsWorked = 1; public $jobPerYear = 1; public $fullTimeEmployment = false; public $freelance= true; public $annualBudget= 10000; public $founding= "2011-08-25"; public $visitsBeforeHire= 12000; public $visitsAfterHire= 23000; public $expenses= 400 ; public $income= 600 ; public $activelyWorking= false; # A Constructor is automatically called when PHP is loaded public function __construct() { # set path for imageDir $this->imagePath = parent::IMAGEDIR . "fruit.jpg"; } } $barrettsFruitProduce = new BarrettsFruitProduce(); class LeisureLife extends Clients { public $category = "apparel"; public $name = "Leisure Life"; public $department = "Branding / Marketing"; public $yearsWorked = 3; public $jobPerYear = 1; public $fullTimeEmployment = true; public $freelance= false; public $annualBudget= 10000; public $founding= "1996-06-06"; public $visitsBeforeHire= 12000; public $visitsAfterHire= 23000; public $expenses= 900 ; public $income= 1500 ; public $activelyWorking= false; # A Constructor is automatically called when PHP is loaded public function __construct() { # set path for imageDir $this->imagePath = parent::IMAGEDIR . "leisurehouse.jpg"; } } $leisureLife = new LeisureLife(); class Nintendo extends Clients { public $category = "gaming"; public $name = "Nintendo"; public $department = "character development"; public $yearsWorked = 1; public $jobPerYear = 8; public $fullTimeEmployment = false; public $freelance= true; public $annualBudget= 10000; public $founding= "1985-01-06"; public $visitsBeforeHire= 800; public $visitsAfterHire= 900; public $expenses = 800 ; public $income = 900 ; public $activelyWorking = true ; # A Constructor is automatically called when PHP is loaded public function __construct() { # set path for imageDir $this->imagePath = parent::IMAGEDIR . "imgres.jpg"; } } $nintendo = new Nintendo(); # Create an array containing all the members classes $companiesNameArray = array($nike, $coffeePress, $barrettsFruitProduce, $leisureLife, $nintendo); // str_replace(search, replace, subject) // echo str_replace($companiesNameArray, $activelyWorking, %client%); $income = array( "Nike" => 500, "CoffeePress" => 2500, "BarrettsFruitProduce" => 600, "LeisureLife" => 1500, "Nintendo" => 900, ); arsort($income); foreach ($income as $key => $val) { echo "$key <i>annual income per year is</i> $$val\n <br /> "; } // # Let's introduce all our full time employment // echo "<h2>Cilents</h2>"; // for ($i=0; $i < count($companies); $i++) { // displayProfile($companies[$companiesName[$i]]); // } // #Let's introduce all of our freelance // echo "<h2>Freelance</h2>"; // for ($i=0; $i < count($companies); $i++) { // displayProfile($companies[$companiesName[$i]]); // } # Display our Jump Menu echo "<form name=\"jump\"> <p align=\"center\"> <select name=\"menu\" onchange='window.location.href=this.options[this.selectedIndex].value'> <option selected>All Members</option> <option value=\"?sort=name\">Sort by Name</option> <option value=\"?sort=nameRev\">Sort by Name (descending)</option> <option value=\"?sort=ageLoToHi\">Sort by Age (youngest to oldest)</option> <option value=\"?sort=ageHiToLo\">Sort by Age (oldest to youngest)</option> <option value=\"?sort=paidLoToHi\">Sort by Paid (highiest paid)</option> <option value=\"?sort=paidHiToLo\">Sort by Paid (lowest paid)</option> </select></p> </form>"; $sort = @$_GET['sort']; # Let's introduce all our members echo "<h2>Clients</h2>"; for ($i=0; $i < count($companiesNameArray); $i++) { switch ( $sort ) { # sort=name -- sorts alphabetically by 'name' in the member array case "name" : sort($companiesNameArray); displayProfile($companies[$companiesNameArray[$i]]); break; case "nameRev" : rsort($companiesNameArray); displayProfile($companies[$companiesNameArray[$i]]); break; # sort=ageLoToHi -- sorts alphabetically by 'age' ascending case "ageLoToHi" : displayProfile($companies[$companiesNameArray[$i]]); break; # sort=ageHiToLo -- sorts alphabetically by 'age' descending case "ageHiToLo" : displayProfile($companies[$companiesNameArray[$i]]); break; # default -- spit out all band members according to their order in the array default : displayProfile($companies[$companiesNameArray[$i]]); break; # sort=paidHiToLo -- sorts lowest paid by 'income' descending case "paidLoToHi" : displayProfile($companies[$companiesNameArray[$i]]); break; # sort=paidHiToLo -- sorts highiest paid by 'income' descending case "paidHiToLo" : displayProfile($companies[$companiesNameArray[$i]]); break; # default -- spit out all band members according to their order in the array default : displayProfile($companiesNameArray[$i]); break; } } # FUNCTIONS - Store all functions down here - I could also store them in another file function displayProfile($company) { echo "<div class='characterProfile'><p>"; # spit out the image echo "<img src=\"".$company->imagePath."\" width=200px /><br />"; # spit out our caption echo "<h3>".$company->name."</h3>"; echo "<i>Company type:</i> ".$company->category."<br />"; echo "<i>Contracting Department:</i> ".$company->department."<br />"; THE FOLLOWING IS SPECIFICALLY WHAT I WANT TO MERGE echo "<pre><i>Company Department:</i> ".array_merge($company->name, $company->department)."<br/>";echo"</pre>"; echo "<i>Jobs per year:</i> ".$company->jobPerYear."<br />"; echo "<i>Company founded:</i> ".displayBusinessAge($company->founding)."<br />"; echo "<i>Age of business: </i> ".calculateAge($company->founding).".<br />"; echo "Number of visits before redesign: ".$company->visitsBeforeHire." per month.<br />"; echo "Number of visits after redesign: ".$company->visitsAfterHire." per month.<br />"; echo "<i>Costs for this project:</i> $".$company->expenses."<br />"; setlocale(LC_MONETARY,"en_US"); echo "<pre><i>Income received: </i> ".money_format( "%i", $company->income."<br />");echo"</pre>"; echo "<i> The Cost-to-Income Ratio for this project was:</i> ".calculateCostToIncome($company->expenses, $company->income)."<br />"; $currentEmployment = str_replace("%client%", "$company->name", "Box Car Studio is not currently working for %client%. <br/>"); if ($company->activelyWorking == true){ $currentEmployment = str_replace(" not ", " ", "$currentEmployment"); } echo $currentEmployment; echo "<i>cost-to-income rato:</i> ".calculateCostToIncome($company->expenses, - $company->income)."<br />"; echo "</p></div>"; } function displayBusinessAge($businessFounding) { # January 1, 1984 $openDateFormatted = date('F j, Y', strtotime($businessFounding)); return $openDateFormatted; } function calculateAge($businessFounding) { #$currentTime = time(); # as a Unix timestamp list($year, $month, $day) = explode("-",$businessFounding); $elapsedYears = date('Y') - $year; $age = $elapsedYears; # calculates number of years elapsed # If current date < opendate (i.e. Oct01 < Dec01), then subtract 1 year if ( date('n') < $month || ( date('n') == $month && date('j') < $day ) ) { $age = $age - 1; } return $age; } function calculateCostToIncome($costs, $income) { $costToIncomeRatio = round($costs / $income, 2); return $costToIncomeRatio; } ?> </div> </body> <script> function fasterFasterAudio() { myAudio.playbackRate = (myAudio.playbackRate + 0.2) % 2.0; } </script> <script type="text/javascript" src="js/bootstrap.js"></script> </html> Quote Link to comment https://forums.phpfreaks.com/topic/284640-how-to-add-function-array_merge/ Share on other sites More sharing options...
Ch0cu3r Posted December 9, 2013 Share Posted December 9, 2013 (edited) I wanted to combine ($company->name, $company->department) together. You use the concatenation operator to combine them together. echo "<pre><i>Company Department:</i> ".$company->name .' '. $company->department."<br/>";echo"</pre>"; array_merge is for merging arrays together, not strings. I guess you are in the same class as JonnyPHP or the same person. Edited December 9, 2013 by Ch0cu3r Quote Link to comment https://forums.phpfreaks.com/topic/284640-how-to-add-function-array_merge/#findComment-1461757 Share on other sites More sharing options...
vinbarbre Posted December 9, 2013 Author Share Posted December 9, 2013 We're very much in the same class. Thanks for the help!! lol Quote Link to comment https://forums.phpfreaks.com/topic/284640-how-to-add-function-array_merge/#findComment-1461882 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.