IB Comp Sci SL - October 11 2016 Lesson Notes: Difference between revisions
Mr. MacKenty (talk | contribs) |
Mr. MacKenty (talk | contribs) |
||
(3 intermediate revisions by the same user not shown) | |||
Line 6: | Line 6: | ||
# Today in class we will start learning about collections and arrays. THESE ARE DIFFERENT. | # Today in class we will start learning about collections and arrays. THESE ARE DIFFERENT. | ||
# If using weapons as array examples offends you, please use [http://mikesrpgcenter.com/bgate/potions.html this potion list as an alternative]. | |||
<syntaxhighlight lang="php"> | <syntaxhighlight lang="php"> | ||
Line 47: | Line 48: | ||
</syntaxhighlight> | </syntaxhighlight> | ||
Below we have an example if an associative array: | |||
<syntaxhighlight lang="php"> | |||
<?php | |||
# this file is used to teach the VERY BASICS of arrays in PHP | |||
$shop_items = array( | |||
"short sword" =>"10", | |||
"dagger" => "2", | |||
"flail" => "12", | |||
"morning star" => "15", | |||
"spear" => "25", | |||
"long bow" => "15", | |||
"crossbow" => "20", | |||
"long sword" => "21", | |||
"two handed sword" => "30", | |||
"scimitar" => "18", | |||
"short bow" => "15", | |||
"staff" => "5", | |||
"club" => "2" | |||
); | |||
# This creates a very simple array. | |||
# We can perform some different operations on this array: | |||
# count the items in the array: | |||
echo "<p>Welcome to our shop. We sell many things for adventurers </p>"; | |||
echo "<p>==========================================</p>"; | |||
# let's list our inventory: | |||
foreach ($shop_items as $i => $cost_of_item) | |||
{ | |||
echo $i . " costs $cost_of_item <br />"; | |||
} | |||
?> | |||
</syntaxhighlight> | |||
</td> | </td> | ||
Line 54: | Line 100: | ||
==[[file:homework.png]] Homework == | ==[[file:homework.png]] Homework == | ||
# Please review our page about [[ | # Please review our page about [[collections]] and [[arrays]] | ||
Latest revision as of 09:28, 11 October 2016
|
|
|
|
||
|
|
|
|