Showing posts with label PHP Associative Array Tutorial. Show all posts
Showing posts with label PHP Associative Array Tutorial. Show all posts

Sunday, April 29, 2012

PHP Associative Array Tutorial


Associative Array
Associative array = Associative word with another word.

In the script below, we create the basis for a Acronym Lookup program in PHP. We will use an associative array to reference the meaning of each acronym, and use the acronym as the associative array's index:

We have three associative arrays: MPLS (links the Multi-Protocol Label Switching), SSTP (links the Secure Socket Tunneling Protocol), and LDAP (links the Lightweight Directory Access Protocol).
Example: 1
<?php
   
   $protocols = array('MPLS'=>'Multi-Protocol Label Switching', 'SSTP'=>'Secure Socket Tunneling Protocol', 'LDAP'=>'Lightweight Directory Access Protocol');
   echo $protocols['MPLS']."<br />";
   echo $protocols['SSTP']."<br />";
   echo $protocols['LDAP'];
?>
Output
Multi-Protocol Label Switching
Secure Socket Tunneling Protocol
Lightweight Directory Access Protocol

Example: 2
<?php
$protocols = array();
$Protocols['MPLS']= 'Multi-Protocol Label Switching';
$Protocols['SSTP']= 'Secure Socket Tunneling Protocol';
$Protocols['LDAP']= 'Lightweight Directory Access Protocol';
echo 'MPLS stands for: '.$Protocols['MPLS']."<br />";
echo 'SSTP stands for: '.$Protocols['SSTP']."<br />";
echo 'LDAP stands for: '.$Protocols['LDAP']."<br />";
?>
Output
MPLS stands for: Multi-Protocol Label Switching
SSTP stands for: Secure Socket Tunneling Protocol
LDAP stands for: Lightweight Directory Access Protocol