PHP Classes

File: example.php

Recommend this page to a friend!
  Classes of Christian Vigh   PHP Associative Array Key Case Insensitive   example.php   Download  
File: example.php
Role: Example script
Content type: text/plain
Description: Example script
Class: PHP Associative Array Key Case Insensitive
Store associative array with case insensitive keys
Author: By
Last change: Update of example.php
Date: 1 year ago
Size: 1,264 bytes
 

Contents

Class file image Download
<?php
   
/***********************************************************************************************************

        The following example demonstrates the use of the AssociativeArray class.
        This example will throw an exception when trying to access undefined index 'ZZ'.

     ***********************************************************************************************************/
   
require ( 'AssociativeArray.phpclass' ) ;

    if (
php_sapi_name ( ) != 'cli' )
        echo (
"<pre>" ) ;

   
$array = new AssociativeArray ( [ 'A' => 'Value of A', 'B' => 'Value of B', 'D' => 'Value of D', 'C' => 'Value of C' ] ) ;

    echo
"Getting value of array['A'] : " . $array [ 'A' ] . "\n" ;
    echo
"Getting value of array['b'] : " . $array [ 'b' ] . "\n" ;

    echo
"********** Unsorted array contents :\n" ;
   
print_r ( $array -> ToArray ( ) ) ;

    echo
"********** Sorted array contents :\n" ;
   
$array -> ksort ( ) ;
   
print_r ( $array -> ToArray ( ) ) ;


    if ( isset (
$array [ 'ZZ' ] ) )
        echo
"Index 'ZZ' exists\n" ;
    else
        echo
"Index 'ZZ' DOES NOT exist\n" ;

   
// The following line of code will throw an exception, because index 'ZZ' is not defined
    //echo "Getting value of (inexisting) array['ZZ'] : " . $array [ 'ZZ' ] . "\n" ;