lecture3 - CPSC431Databasesand Applications Lecture3...

Info iconThis preview shows pages 1–9. Sign up to view the full content.

View Full Document Right Arrow Icon
CPSC431 Databases and  Applications Lecture 3
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Multidimensional Arrays $states = array ( "Ohio" => array ("population" => "11,353,140", "capital" => "Columbus"), "Nebraska" => array("population" => "1,711,263", "capital" => "Omaha") ) You could then reference Ohio's population like so: $states["Ohio"]["population"] This would return the following value: 11,353,140
Background image of page 2
Array Related Functions array() $languages = array ("English", "Gaelic", "Spanish"); $languages = array ("Spain" => "Spanish", "Ireland" => "Gaelic", "United States" => "English"); // $languages["Spain"] = "Spanish“ // $languages["Ireland"] = "Gaelic“
Background image of page 3

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Array Related Functions list() Suppose the following data are in the file Nino Sanzi|Professional Golfer|green while ($line = fgets ($user_file, 4096)) { // use explode() to separate each piece of data. list ($name, $occupation, $color) = explode ("|", $line); // format and output the data print "Name: $name <br />"; print "Occupation: $occupation <br />"; print "Favorite color: $color <br />"; } Each line would in turn be read and formatted similar to this: Name: Nino Sanzi Occupation: Professional Golfer Favorite Color: green
Background image of page 4
Array Related Functions range() $die = range(0,6); // Same as specifying $die = array(0,1,2,3,4,5,6) $even = range(0,20,2); // $even = array(0,2,4,6,8,10,12,14,16,18,20); $letters = range("A","F"); // $letters = array("A,","B","C","D","E","F");
Background image of page 5

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Array Related Functions array_push() //add to the end $states = array("Ohio","New York"); array_push($states,"California","Texas"); // $states=array("Ohio","New York","California","Texas"); array_pop() //get from the end $states = array("Ohio","New York","California","Texas"); $state = array_pop($states); // $state = "Texas"
Background image of page 6
Array Related Functions array_shift() //get from the front $states = array("Ohio","New York","California","Texas"); $state = array_shift($states); // $states = array("New York","California","Texas") // $state = "Ohio" array_unshift() //add to the front $states = array("Ohio","New York"); array_unshift($states,"California","Texas"); // $states = array("California","Texas","Ohio","New York"); array_pad() //pad the array to a specific length $states = array("Alaska","Hawaii"); $states = array_pad($states,4,"New colony?"); $states = array("Alaska","Hawaii","New colony?","New colony?");
Background image of page 7

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Array Related Functions In_array() $grades = array(100,94.7,67,89,100); if (in_array("100",$grades)) echo "Sally studied for the test!"; if (in_array("100",$grades,1)) echo "Joe studied for the test!"; This returns: Sally studied for the test! Array_keys()
Background image of page 8
Image of page 9
This is the end of the preview. Sign up to access the rest of the document.

Page1 / 26

lecture3 - CPSC431Databasesand Applications Lecture3...

This preview shows document pages 1 - 9. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online