PHP array example
Hello all. It’s been a few weeks since I posted… I’ve been teaching myself PHP to create a web interface for a Asterisk based project I’m working on. My goal is to create a LAMP(Linux, Apache, MySQL, PHP) web managment tool for creating calling cards for use with Asterisk. The project is called ACCWA(pronounced aqua), the Asterisk Calling Card Web Administration tool. As I put this altogether I will keep my loyal readers updated about what I’ve learned about PHP.
Today I will cover Arrays. PHP handles arrays in manner similar to PERL. Each value can have an optional indice. In my example below, we simply have a list with no idiceses.
example:
<?php
$myarray[]=”hi” ;
$myarray[]=”how” ;
$myarray[]=”are” ;
$myarray[]=”you?” ;
// Now we will ‘echo’ each value in the array
foreach ($myarray as $i) {
echo “$i ” ; }
?>
output of myarray.php:
Above we did two simple task. First we defined a list of words in our array, then we echo’ed each one individually with the ‘foreach’ function. Very similar to BASH. Your PHP page should display:
hi how are you?