From Computer Science Wiki
|
|
Line 47: |
Line 47: |
|
| |
|
| </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> |
Revision as of 09:19, 11 October 2016
What are we going to learn today?[edit]
- Today in class we will start learning about collections and arrays. THESE ARE DIFFERENT.
<?php
# this file is used to teach the VERY BASICS of arrays in PHP
$shop_items = array(
"short sword",
"dagger",
"flail",
"morning star",
"spear",
"long bow",
"crossbow",
"long sword",
"two handed sword",
"scimitar",
"short bow",
"staff",
"club"
);
# 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:
for ($i = 0; $i < count($shop_items); $i++)
{
echo $i . " - $shop_items[$i] <br />";
}
?>
Below we have an example if an associative array:
<?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 />";
}
?>
|
Homework[edit]
- Please review our page about What is a programming language?
|
How am I being assessed today?[edit]
- You will be formatively assessed in class today
|
Standards we are covering today[edit]
|
As a computer scientist, you have:[edit]
- Confidence in dealing with complexity
- Persistence in working with difficult problems
- Tolerance for ambiguity
- The ability to deal with open-ended problems
- The ability to communicate and work with others to achieve a common goal or solution
|
Credits[edit]
|