Announcements | Last Post | |
---|---|---|
SoC Curricula | 09/30/2017 01:08PM | |
Demarcation or scoping of examinations and assessment | 02/13/2017 07:59AM | |
School of Computing Short Learning Programmes | 11/24/2014 08:37AM | |
Unisa contact information | 07/28/2011 01:28PM |
Section 6 - Arrays in PHP July 17, 2013 07:49PM |
Registered: 10 years ago Posts: 22 Rating: 0 |
Re: Section 6 - Arrays in PHP July 17, 2013 08:53PM |
Registered: 10 years ago Posts: 37 Rating: 0 |
Re: Section 6 - Arrays in PHP July 18, 2013 10:00AM |
Registered: 11 years ago Posts: 73 Rating: 0 |
Language: PHP<?php echo "<h1><span style=\"color: red;\">TABLE PRINT FUNCTION</h1></span>"; $txt0 = "Things to know bout me"; $txt1 = "I Love my University UNISA & UNIX/Linux OS"; $txt2 = "I know HTML5, CSS3 & JavaScript"; $txt3 = "I am studying PHP"; function tableWrap($txt0, $txt1, $txt2, $txt3,){ echo "<p><span style=\"color: blue;\">things to know about me!!</p></br>"; echo "<table style=\"border: 1px solid #000;\">"; echo "<tr><th style=\"border: 1px solid #000;\">".$txt0."</tr></th>"; echo "<tr><td style=\"border: 1px solid #000;\">".$txt1."</tr></td>"; echo "<tr><td style=\"border: 1px solid #000;\">".$txt2."</tr></td>"; echo "<tr><td style=\"border: 1px solid #000;\">".$txt3."</tr></td>"; echo "</table>"; } #function call on variables listed above tableWrap($txt1, $txt1, $txt2, $txt3); ?>
Re: Section 6 - Arrays in PHP July 18, 2013 03:08PM |
Registered: 10 years ago Posts: 38 Rating: 0 |
Re: Section 6 - Arrays in PHP July 18, 2013 04:27PM |
Registered: 11 years ago Posts: 73 Rating: 0 |
Language: PHP<?php $a = 1; $b = 2; function Sum(){ global $a, $b; #the "global" keyword is useful for referencing variables outside of the function';s scope, and you can list as many variables as you like as long as you separate with commas $b = $a + $b; } Sum(); echo $b; ?>
Language: PHP<?php function test(){ static $a = 0; #The "static" keyword remembers the variable $a giving it a longer life span echo $a; $a++; #each time this function is called it is incremented and the static keyword will remember that number each time the function is called } ?>
Re: Section 6 - Arrays in PHP July 19, 2013 04:58PM |
Registered: 10 years ago Posts: 37 Rating: 0 |
Re: Section 6 - Arrays in PHP July 20, 2013 02:24PM |
Registered: 11 years ago Posts: 123 Rating: 0 |
Re: Section 6 - Arrays in PHP July 22, 2013 05:35PM |
Registered: 11 years ago Posts: 73 Rating: 0 |
Language: PHP<?php $yearOfBirth = array( "Sipho" => 2000, "Charles" => 2001, "Rushil" => 2002 ); function myAge ($array, $key){ #A function called myAge() that returns your age $currentYear = 2013; foreach($array as $key=>$year){ #Here we loop through an associative array to find a match for your date of birth $myYear = $year; #The output from foreach is initiated to the $myYear variable. } return $currentYear - $myYear; #Here we return the calculation to the call } $myAge = myAge($yearOfBirth, "Charles" ); #Here I initiate the variable $myAge with the produce returned from the myAge() function.. echo "Hi my name is Charles and Iam ".$myAge."yrs old"; #Now we print your age!! ?>
Re: Section 6 - Arrays in PHP July 22, 2013 10:08PM |
Registered: 11 years ago Posts: 123 Rating: 0 |
Re: Section 6 - Arrays in PHP July 23, 2013 08:58AM |
Registered: 11 years ago Posts: 73 Rating: 0 |
Re: Section 6 - Arrays in PHP July 23, 2013 10:43AM |
Registered: 11 years ago Posts: 73 Rating: 0 |
Language: PHP<?php $superHeros = array( $Hulk = array("Skill"=>"Superhuman strength", "Skin Colour" => "Green", "Country"=>"United States"), $Superman = array("Skill"=>"Superhuman Strength", "Skin Colour"=>"White", "Country"=>"United States"), $Tony_Stark = array("Skill"=>"Nano_Technology", "Skin Color"=>"White", "Country"=>"United States") ); echo "My Question is how do I loop through the above Multidimensional array printing the Super Hero';s name and traits?"; ?>
Re: Section 6 - Arrays in PHP July 23, 2013 12:53PM |
Registered: 11 years ago Posts: 68 Rating: 0 |
Re: Section 6 - Arrays in PHP July 23, 2013 12:57PM |
Registered: 11 years ago Posts: 68 Rating: 0 |
Re: Section 6 - Arrays in PHP July 23, 2013 01:09PM |
Admin Registered: 11 years ago Posts: 6,606 Rating: 396 |
Re: Section 6 - Arrays in PHP July 23, 2013 01:31PM |
Registered: 11 years ago Posts: 68 Rating: 0 |
Re: Section 6 - Arrays in PHP July 23, 2013 02:30PM |
Registered: 11 years ago Posts: 68 Rating: 0 |
Re: Section 6 - Arrays in PHP July 23, 2013 03:00PM |
Registered: 11 years ago Posts: 73 Rating: 0 |
Language: PHP<!DOCTYPE HTML> <HTML> <HEAD> <TITLE>Array_Loop_Print</TITLE> </HEAD> <BODY> <?PHP $superheros=array( $hulk=array( "AKA"=>"BIG BOY", "Traits"=>"Superhuman Strength", "Occupation"=>"Superhero", "Skin Color"=>"Green", "Known Weakness"=>"N/A", "Country of Birth"=>"United States" ), $superman=array( "AKA"=>"Clark Kent", "Traits"=>"Superhuman Strength", "Occupation"=>"Superhero", "Skin Color"=>"White", "Known Weakness"=>"Cryptonite", "Country of Birth"=>"United States" ), $Ironman=array( "AKA"=>"Tony Stark", "Traits"=>"Nano Technology", "Occupation"=>"Superhero", "Skin Color"=>"White", "Known Weakness"=>"Valnurable when outside of suit", "Country of Birth"=>"United States" ), ); foreach($superheros as $name){ while(list($key, $value)=each($name)){ echo $key ." = ". $value."<br>"; } echo "<br>"; } ?> </BODY> </HTML>
Re: Section 6 - Arrays in PHP July 23, 2013 03:36PM |
Registered: 11 years ago Posts: 68 Rating: 0 |
Re: Section 6 - Arrays in PHP July 23, 2013 04:16PM |
Registered: 11 years ago Posts: 73 Rating: 0 |
Language: PHP<?php $myArray = array( $array1 = array("name"=>"firstArray"), $array2 = array("name"=>"secondArray") ); foreach($myArray as $array){ #this is the one we';re all familier with (no need to explain here) while(list($key,$value)=each($array)){ #my condition that will execute the following expression as long as true echo "I am the ".$value." and i live inside ".$key; #pay close attention to how I use the list() & each() functions to list every instance and value of each $array occurance } } ?>
Re: Section 6 - Arrays in PHP July 23, 2013 05:32PM |
Registered: 11 years ago Posts: 73 Rating: 0 |
Language: PHP<?php $superHeros = array( "Hulk" => array("Skill"=>"Superhuman strength", "Skin Colour" => "Green", "Country"=>"United States"), "Superman" => array("Skill"=>"Superhuman Strength", "Skin Colour"=>"White", "Country"=>"United States"), "Tony Stark" => array("Skill"=>"Nano_Technology", "Skin Color"=>"White", "Country"=>"United States") ); foreach ($superHeros as $name => $traits) { echo "CodeName: ".$name . "<br>"; foreach ($traits as $traits => $type) { echo $traits." - > ".$type."<br>"; } echo "<br>"; } ?>
Re: Section 6 - Arrays in PHP July 23, 2013 05:39PM |
Admin Registered: 18 years ago Posts: 10,001 Rating: 353 |
Re: Section 6 - Arrays in PHP July 23, 2013 05:58PM |
Registered: 10 years ago Posts: 17 Rating: 0 |
Re: Section 6 - Arrays in PHP July 23, 2013 06:55PM |
Registered: 11 years ago Posts: 123 Rating: 0 |
Re: Section 6 - Arrays in PHP July 23, 2013 07:35PM |
Registered: 10 years ago Posts: 22 Rating: 0 |
Re: Section 6 - Arrays in PHP July 24, 2013 12:43PM |
Registered: 11 years ago Posts: 73 Rating: 0 |
Re: Section 6 - Arrays in PHP July 26, 2013 09:38AM |
Registered: 11 years ago Posts: 36 Rating: 0 |
Re: Section 6 - Arrays in PHP July 27, 2013 08:58PM |
Registered: 10 years ago Posts: 22 Rating: 0 |
Re: Section 6 - Arrays in PHP July 28, 2013 09:34PM |
Registered: 10 years ago Posts: 22 Rating: 0 |
Re: Section 6 - Arrays in PHP July 30, 2013 02:45PM |
Registered: 10 years ago Posts: 17 Rating: 0 |
Language: PHP$my_sites = array( ';papias'; => ';www.papias.co.za';, ';spha'; => ';www.spha.co.za';, ';jessy'; => ';www.jessy.co.za'; ); foreach ($my_sites as $name => $website) { echo "<li><a href=';$website';>" . ucwords($name) . "</a></li>"; //echo "<pre><a href=';$website';>" . ucwords($name) . "</a></pre>"; }
Re: Section 6 - Arrays in PHP July 30, 2013 03:58PM |
Registered: 11 years ago Posts: 73 Rating: 0 |
Language: PHP<?PHP #the following must be enabled in the php.ini otherwise stick to the <?PHP?> tags....... $status="I am surrounded by a bunch of <?PHP?> tags, these tags could also be written in C# style like <%%> or just like this <??>"; echo "I hope the above explanation helps you bud"; ?>
Language: PHP$mySites = array( "unisa" => "http://www.unisa.ac.za", "codecademy" => "http://www.codecademy.co.za" ); foreach ($mySites as $key => $value){ echo "The ".strtoupper($name)." website can be found "."<a href=\"".$value."\">here</a><br>"; }
Re: Section 6 - Arrays in PHP July 30, 2013 06:50PM |
Registered: 10 years ago Posts: 17 Rating: 0 |
Language: PHP<pre><?php $my_lessons = array( ';papias'; => ';www.google.co.za';, ';sipho'; => ';www.fnb.co.za';, ';jessy'; => ';www.yahoo.co.za'; ); ?></pre>
Language: PHP<?php $my_lessons = array( ';papias'; => ';www.google.co.za';, ';sipho'; => ';www.fnb.co.za';, ';jessy'; => ';www.yahoo.co.za'; ); echo "<pre><a href=';$website';>" . ucwords($name) . "</a></pre>"; ?>
Re: Section 6 - Arrays in PHP July 30, 2013 07:34PM |
Registered: 12 years ago Posts: 115 Rating: 0 |
.Quote
http://www.youtube.com/watch?v=9AnuVr9CWNM
Re: Section 6 - Arrays in PHP July 30, 2013 08:27PM |
Registered: 10 years ago Posts: 56 Rating: 0 |
Re: Section 6 - Arrays in PHP July 31, 2013 09:37AM |
Registered: 11 years ago Posts: 73 Rating: 0 |
Language: PHP<?PHP #Placing the HTML <pre></pre> tags here will result in an error as this section is the actual PHP script and the PHP parser wont know what to do with it.. $myMovies = array("300", "Troy", "Spartacus" ); for (counter=0; counter <=3; counter++){ if($myMovies[counter]){ echo "<pre>".$myMovies[counter]."</pre><br>"; #This section feeds HTML to the browser so it makes sence to place the HTML <pre></pre> tags here... } } ?>
Re: Section 6 - Arrays in PHP July 31, 2013 07:46PM |
Registered: 11 years ago Posts: 21 Rating: 0 |
Language: PHP<?PHP $status = array(';unchecked';,';unchecked';,';unchecked';,';unchecked';,';unchecked';); if (isset($_POST[';Submit1';])) { if (isset($_POST[';box';])) //checking if the array exist incase no checkboxes were selected initially { $checked = $_POST[';box';]; //returning an aray $checked of checkboxes selected for($i=0; $i < count($checked); $i++) //looping through the $checked array { //echo "Selected " . $checked[$i] . "<br>"; //checking purposes only that the correct checkbox value is displayed. switch($checked[$i]) { case ';net';: $status[0] = ';checked';; print "Vbasic.net was checked <br>"; //checking purposes only break; case ';word';: $status[1] = ';checked';; print "Microsoft Word was checked <br>"; //checking purposes only break; case ';excel';: $status[2] = ';checked';; print "Microsoft Excel was checked <br>"; //checking purposes only break; case ';web';: $status[3] = ';checked';; print "Web Design was checked <br>"; //checking purposes only break; case ';php';: $status[4] = ';checked';; print "PHP for beginners was checked <br>"; //checking purposes only break; } } } //else //{ //print "no array exists"; //this is for checking purposes only //} } ?>
Language: HTML<FORM NAME ="form1" METHOD ="POST" ACTION ="testing2.php"> <Input type = ';Checkbox'; Name ="box[]" value ="net" <?PHP print $status[0]; ?>>Visual Basic .NET <P> <Input type = ';Checkbox'; Name ="box[]" value="word" <?PHP print $status[1]; ?>>Microsoft Word <P> <Input type = ';Checkbox'; Name ="box[]" value="excel" <?PHP print $status[2]; ?>>Microsoft Excel <P> <Input type = ';Checkbox'; Name ="box[]" value="web" <?PHP print $status[3]; ?>>Web Design <P> <Input type = ';Checkbox'; Name ="box[]" value="php" <?PHP print $status[4]; ?>>PHP for the Beginner <P> <INPUT TYPE = "Submit" Name = "Submit1" VALUE = "Choose your books"> </FORM>
Re: Section 6 - Arrays in PHP July 31, 2013 08:22PM |
Registered: 10 years ago Posts: 17 Rating: 0 |
Re: Section 6 - Arrays in PHP August 01, 2013 09:20AM |
Registered: 11 years ago Posts: 73 Rating: 0 |
Language: PHP<?php $seasons = array("Autumn", "Winter", "Spring", "Summer"); $array_count = count($seasons); for ($key_Number = 0; $key_Number < $array_count; $key_Number++) { print $seasons[$key_Number]."<br>"; } ?>
Re: Section 6 - Arrays in PHP August 05, 2013 06:23PM |
Registered: 10 years ago Posts: 12 Rating: 0 |
Re: Section 6 - Arrays in PHP August 06, 2013 07:07PM |
Registered: 11 years ago Posts: 39 Rating: 0 |
Re: Section 6 - Arrays in PHP August 06, 2013 07:32PM |
Registered: 11 years ago Posts: 73 Rating: 0 |
Language: PHP<?php $full_name = array( ); $full_name["David"]="Gilmour"; $full_name["Nick"]="Mason"; $full_name["Roger"]="Waters"; $full_name["Richard"]="Wright"; foreach($full_name as $key_name => $key_value) { print "Key = ".$key_name." Value = ".$key_value."<br />"; } ?>
Re: Section 6 - Arrays in PHP August 07, 2013 03:43PM |
Registered: 10 years ago Posts: 37 Rating: 0 |
Re: Section 6 - Arrays in PHP August 09, 2013 05:09PM |
Registered: 10 years ago Posts: 57 Rating: 0 |
Re: Section 6 - Arrays in PHP August 10, 2013 10:13AM |
Registered: 11 years ago Posts: 39 Rating: 0 |
Re: Section 6 - Arrays in PHP August 12, 2013 11:07AM |
Registered: 13 years ago Posts: 55 Rating: 0 |
Re: Section 6 - Arrays in PHP August 14, 2013 04:45PM |
Registered: 11 years ago Posts: 44 Rating: 0 |
Re: Section 6 - Arrays in PHP August 18, 2013 03:35PM |
Registered: 10 years ago Posts: 57 Rating: 0 |
Language: PHPprint $seasons[2] . " "; print $seasons[3];
Re: Section 6 - Arrays in PHP August 18, 2013 04:05PM |
Registered: 10 years ago Posts: 57 Rating: 0 |
Re: Section 6 - Arrays in PHP August 19, 2013 08:38AM |
Admin Registered: 18 years ago Posts: 10,001 Rating: 353 |
>Language: PHP> print $seasons[2] . " "; > print $seasons[3]; >
Re: Section 6 - Arrays in PHP August 19, 2013 08:43AM |
Admin Registered: 18 years ago Posts: 10,001 Rating: 353 |
Re: Section 6 - Arrays in PHP August 19, 2013 09:58PM |
Registered: 10 years ago Posts: 57 Rating: 0 |