Mega Code Archive

 
Categories / Php / Data Type
 

Using array_merge() and the + operator with associative arrays as well

<?php      function array_display($array, $pre=FALSE) {          $tag = $pre ? 'pre' : 'p';          printf("<%s>%s</%s>\n", $tag, var_export($array, TRUE), $tag);      }      $dogs1 = array('A' => 'C', 'B' => 'C', 'D' => 'C');      $dogs2 = array('a' => 'a', 'b' => 'b');         array_display(array_merge($dogs1, $dogs2), TRUE);     array_display($dogs1 + $dogs2, TRUE);  ?>