array_change_key_case()array_chunk()array_combine()array_count_values()array_diff()array_diff_assoc()array_diff_key()array_fill()array_flip()array_interset()array_intersect_assoc()array_intersect_key()array_key_exists()array_merge()array_pad()array_product()array_rand()array_search()array_slice()array_sum()array_unique()in_array()range()shuffle()
Array::PAT - PHP Array Tools - Perl extension for array functions that are built into PHP.
use Array::PAT;
@array = @array = qw(foo bar foo bar foo); $result = in_array("foo", @array); @duplicates_removed = array_unique(@array); @merged = array_merge(@array, @duplicates_removed); @foo = array_pad(17, 3, @array); @shuffled = shuffle(@foo); %result = array_count_values(@shuffled); ...
This module is designed to give Perl the same array functionality that can be found in PHP. In PHP, hashes are called associative arrays and are treated similarly to numeric arrays. As is such, some of these functions will work with hashes or arrays. Just as The Beatles say:
"And in the end, the love you take,
is equal to the love you make" - "The End", John Lennon/Paul McCartney (1969)
array_change_key_case()%changed = array_change_key_case($case, %hash);
---OR---
$hash_ref = array_change_key_case($case, \%hash);$case to 1. To make the keys lowercase, set $case to 0.
The function will leave number indices as is.
array_chunk()
@return = array_chunk($size, @array);
---OR---
$reference = array_chunk($size, \@array);
array_combine()$hash_ref = array_combine(\@keys, \@values);
array_count_values()%return = array_count_values(@array);
array_diff()@return = array_diff(@array1, @array2);
---OR---
$array_reference = array_diff(\@array1, \@array2);
array_diff_assoc() %return = array_diff_assoc(\%hash1, \%hash2, $return);
---OR---
$hash_ref = array_diff_assoc(\%hash1, \%hash2);array_diff(). If you specify $return to be 1,
it will return a hash. If $return is omitted or specified to be 0, you will recieve a hash reference.
array_diff_key() %return = array_diff_key(\%hash1, \%hash2, $return);
---OR---
$hash_ref = array_diff_key(\%hash1, \%hash2);array_diff() except the comparison is done on the keys instead
of the values. Strict type check is executed so the string representation must be the same. If you specify $return to be 1,
it will return a hash. If $return is omitted or specified to be 0, you will recieve a hash reference.
array_fill()@array = array_fill($start, $num, $value, $return);
---OR---
$array_ref = array_fill($start, $num, $value);$return to be 1,
it will return an array. If $return is omitted or specified to be 0, you will recieve an array reference.
array_flip()%flipped = array_flip(%hash);
---OR---
$hash_ref = array_flip(\%hash);
array_interset()@return = array_intersect(\@array1, \@array2, $return);
---OR---
$array_ref = array_intersect(\@array1, \@array2);$return to be 1, it will return an array. If $return is omitted or specified to be 0, you will recieve an array
reference.
array_intersect_assoc() %return = array_intersect_assoc(\%hash1, \%hash2, $return);
---OR---
$hash_ref = array_intersect_assoc(\%hash1, \%hash2);array_intersect(). if you specify $return to be 1, it will return a hash. If $return is omitted
or specified to be 0, you will recieve a hash reference.
array_intersect_key() %return = array_intersect_key(\%hash1, \%hash2, $return);
---OR---
$hash_ref = array_intersect_key(\%hash1, \%hash2);$return to be 1, it will return a hash. If $return
is omitted or specified to be 0, you will recieve a hash reference.
array_key_exists()$return = array_key_exists($key, 1, @array);
---OR---
$return = array_key_exists($key, 2, %hash);
---OR---
$return = array_key_exists($key, \@array);
---OR---
$return = array_key_exists($key, \%hash);
array_merge()@array_merged = array_merge(@array1, @array2);
---OR---
@array_merged = array_merge(\@array1, \@array2);
array_pad()@padded_array = array_pad($pad_size, $pad_value, @array);
---OR---
$array_ref = array_pad($pad_size, $pad_value, \@array);
array_product()$product = array_product(@array);
---OR---
$product = array_product(\@array);
array_rand()@random = array_rand($number, 1, @array);
---OR---
@random = array_rand($number, 2, %hash);
---OR---
$array_ref = array_rand($number, \@array);
---OR---
$array_ref = array_rand($number, \%hash);
array_search()$return = array_search($needle, @haystack);
---OR---
$return = array_search($needle, \@haystack);
array_slice()@return = array_slice($offset, $length, @array);
---OR---
$array_ref = array_slice($offset, $length, \@array);
array_sum()$sum = array_sum(@array);
---OR---
$sum = array_sum(\@array);
array_unique()@duplicates_removed = array_unique(@array);
---OR---
$array_ref = array_unique(\@array);
in_array()$return = in_array($needle, @haystack);
---OR---
$return = in_array($needle, \@haystack);
range()$array_ref = range($low, $high, $step);
---EXAMPLE---
$array_ref = range('a','m', 2);
---OR---
$array_ref = range(100, 2, 6);
shuffle()@shuffled = shuffle(@array);
---OR---
$array_ref = shuffle(\@array);