This is an old revision of the document!
In this activity you will learn some advanced array techniques for arrays in PHP, which will be useful when processing data from a database.
<?php include('header.php'); include('menu.php'); ?> <main> </main> <?php include('footer.php'); ?>
$animals = array('dog', 'elephant', 'rabbit');
$animals = array('item1' => 'dog', 'item2' => 'elephant', 'item3' => 'rabbit');
<main>
tag.echo $animals;
echo
doesn't work for arrays.print_r($animals);
print_r
is a $animals['item1'] = 'dog'; $animals['item2'] = 'elephant'; $animals['item3'] = 'rabbit';
<main>
tag.echo "MURRAY: the first item of animals is $animals['item1'].";
<main>
tag after creating your array.foreach($animals as $name => $item) { echo "MURRAY: $name is a $item"; }
$animals
, where the reference for each item is $name
and the item itself is $item
'.$name
and $item
.echo
then display these values so that we can read them in the HTML code.$i = 0; while ($i < 10) { error_log("MURRAY: the value of i is $i"); $i++; }
$i = 0;
defines a variable and sets it to '0'.while ($i < 10) {}
runs the code inside {}
as long as $i is less than 10.error_log("MURRAY: the value of i is $i");
outputs a string containing the value of $i
to the logs so we can see it.$i++;
increments $i
each loop so that it doesn't go on forever.cat /var/log/apache2/error.log | grep 'MURRAY'