PHP file – Creation

For my PHP file i decided to create a simple array, a PHP array is simply a list of information or a map of information. Arrays within PHP have many different uses such as a list, hash table, dictionary, collection and a stack. Arrays are created from various different key casts such as:

  • Strings – Valid integers
  • Floats – Fractional integers
  • Bools – cast as integers too, true will be stored as 1 and false 0
  • Null – Empty strings

I decided to create a simple array that listed a group of people and told them their age and where they’re from:

<!DOCTYPE html>
<html>
<body>

<?php
$people = array
(
array(“Toby”,19,”London”),
array(“Max”,21,”Pulborough”),
array(“Lucy”,20,”Bournemouth”),
array(“Rob”,24,”York”),
);

for ($row = 0; $row < 4; $row++) {
echo “<p><b>Person $row</b></p>”;
echo “<ul>”;
for ($col = 0; $col < 3; $col++) {
echo “<li>”.$people[$row][$col].”</li>”;
}
echo “</ul>”;
}
?>

</body>
</html>

here is the finished product:

Person 0

  • Toby
  • 19
  • London

Person 1

  • Max
  • 21
  • Pulborough

Person 2

  • Lucy
  • 20
  • Bournemouth

Person 3

  • Rob
  • 24
  • York
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s