Designing solutions through programming - October 14 2016 Lesson Notes
What are we going to learn today?[edit]
<?php
$player_inventory = array
(
"sword",
"shield",
"armour",
"potion of healing",
"amulet"
);
echo "You are currently carrying:<br /> ";
for ($i=0; $i < count($player_inventory); $i++)
{
echo $player_inventory[$i] . "<br />";
}
# here is where we add an item to our array:
array_push($player_inventory, "magic ring", "wand");
# now let's look at the new inventory:
echo "<br />This is the new inventory, after we have pushed the new items to the end of the array<br /> ";
for ($i=0; $i < count($player_inventory); $i++)
{
echo $player_inventory[$i] . "<br />";
}
# now we will use common access methods:
echo "<br />Below we see how common access methods work.<br /><br />";
echo "The index is CURRENTly pointing at: " . current($player_inventory);
echo "<br />";
echo "The NEXT index (relative to the current index) is: " . next($player_inventory);
echo "<br />";
echo "The index is now CURRENTly pointing at: " . current($player_inventory);
echo "<br />";
echo "The previous index is: " . prev($player_inventory);
echo "<br />";
echo "The current index is: " . current($player_inventory);
echo "<br />";
echo "The last element in the list is " . end($player_inventory);
echo "<br />";
echo "The current element is: " . current($player_inventory);
echo "<br />";
echo "The first element in the list is: " . reset($player_inventory);
?>
|
Homework[edit]
|
|
How am I being assessed today?[edit]
|
||
Standards we are covering today[edit]
|
As a computer scientist, you have:[edit]
|
|
Credits[edit] |