Web Design and Programming Pt 4 PHP Arrays

Illustration of the brainIn this video tutorial I’ll show you how to use arrays using the PHP programming language.

Specifically I cover:

  • How to create an array
  • How to search for information stored in an array
  • How to cycle through an array with the foreach loop
  • And more…

The code proceeds the video and you can use it in anyway you see fit. If you have any questions or comments leave them below.

Code From the Video

<title><?php echo “Arrays”;?></title>


$myInfo = array(“Name” => “Derek”, “Street” => “123 Main”, “City” => “Pittsburgh”);
echo “My name is “, $myInfo[“Name”], “<br /><br />”;

$moreInfo = array(“State” => “PA”, “Age” => 35);

$myInfo = array_merge($myInfo, $moreInfo);

foreach( $myInfo as $key => $value)
echo $key, ” “, $value, “<br />”;
echo “<br /><br />”;

if(array_key_exists(“Name”, $myInfo)) echo “The name stored is “, $myInfo[“Name”];
echo “<br /><br />”;

$citySearch = array_search(“Pittsburgh”, $myInfo);
echo “The key for the city is “, $citySearch;
echo “<br /><br />”;

echo “<br /><br />”;

echo “<br /><br />”;

$customer1 = array(“Name” => “Derek”, “Street” => “123 Main”, “City” => “Pittsburgh”);
$customer2 = array(“Name” => “Sally”, “Street” => “23 Main”, “City” => “Pittsburgh”);

$customers = array($customer1, $customer2);
echo “<br /><br />”;

foreach($customers as $key)
foreach($key as $key2 => $value)
echo $key2, ” “, $value, “<br />”;



2 Responses to “Web Design and Programming Pt 4 PHP Arrays”

  1. Warren says:

    Hi there

    Firstly thanks so much for sharing this video set, it’s been a great point of reference.

    Just a quick question, I’m trying to use the variable structures used above in a form and I’m not sure if I’m heading in the right direction. Please let me know it I am.

    Here is my code.

    Who is this form going to?

    <option value="”>
    <option value="”>
    <option value="”>
    <option value="”>
    <option value="”>
    <option value="”>
    <option value="”>

    I’m trying to create a multidimentional array and calling specific key’s via the form, which will store information in a MySQL database which has the appropriate values.

    Hope I’m making sence.


  1. Tweets that mention Web Design and Programming Pt 4 PHP Arrays | New Think Tank -- Topsy.com - [...] This post was mentioned on Twitter by Huzaifa Ali, Daniel Taylor. Daniel Taylor said: Web Design and Programming Pt…

Leave a Reply to Warren Cancel reply

Your email address will not be published.