PEAK XOOPS - a useful function array_map() in englishin japanese

Archive | RSS |
PHP : a useful function array_map()
Poster : GIJOE on 2007-03-20 13:06:04 (12625 reads)

in englishin japanese
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 ) ) ) ) ;

Printer friendly page Send this story to a friend

Comments list

Username or e-mail:


Remember Me

Lost Password?

Register now!