a useful function array_map()
Date 2007-03-20 13:06:04 | Category: PHP
|
array_map() the built-in function of PHP is fast and useful one.
eg1) fetching an array of integer from a textbox. [1,2,3,4] You can get it by just a line.
$myarray = array_map( 'intval' , explode( ',' , $post_data ) ) ;
eg2) merging arrays with unique elements of arrays or objects Neither "operator +" nor array_merge() are enough for the purpose. You can use array_map() usefully like this.
$merged_array = array_map( 'unserialize' , array_unique( array_map( 'serialize' , array_merge( $array1 , $array2 ) ) ) ) ;
|
|