PHP Classes

File: examples/MergeAssoc.php

Recommend this page to a friend!
  Classes of Christian Vigh   PHP Array Helpers   examples/MergeAssoc.php   Download  
File: examples/MergeAssoc.php
Role: Example script
Content type: text/plain
Description: Example script
Class: PHP Array Helpers
Perform several array manipulation operations
Author: By
Last change: Update of examples/MergeAssoc.php
Date: 1 year ago
Size: 1,034 bytes
 

Contents

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

        The following example demonstrates the use of the ArrayHelpers::MergeAssoc function.

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

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

   
$array_1 = [ 17 => 'value 17 version 1' ] ;
   
$array_2 = [ 17 => 'value 17 version 2', 18 => 'value 18' ] ;
   
$array_3 = [ 1 => 'value 1', 19 => 'value 19', 20 => 'value 20' ] ;

    echo
"***** Merging the following arrays :\n" ;
    echo
"array 1 : " ; print_r ( $array_1 ) ;
    echo
"array 2 : " ; print_r ( $array_2 ) ;
    echo
"array 3 : " ; print_r ( $array_3 ) ;
    echo
"***** Result of ArrayHelpers::MergeAssoc :\n" ;
   
print_r ( ArrayHelpers::MergeAssoc ( $array_1, $array_2, $array_3 ) ) ;
    echo
"***** Result of array_merge() :\n" ;
   
print_r ( array_merge ( $array_1, $array_2, $array_3 ) ) ;