3.16 Perl-Based Array Manipulation Features


You're a "Perl monger" and you want to know what array features PHP has that are related to Perl.

Technique

Here is a list of all the Perl-related array manipulation features, as well as (in the "Discussion" section) a list of incompatibilities with their Perl counterparts.

Perl Function PHP Function(s)
pop() array_pop()
push() array_push()
shift() array_shift()
unshift() array_unshift()
splice() array_splice()
join() join() , implode()
grep() preg_grep()
keys() array_keys()
each() each()
values() array_values()
reverse() array_reverse()
sort () usort() (to some extent)

Comments

There are some incompatibilities between certain functions; for example, between Perl's push() function and PHP's array_push() function. This is more of a general incompatibility . In Perl, arrays specified in list context are automatically flattened, so

 push (@list1, @list2); 

would combine the two arrays ”the same thing that array_merge() would do in PHP. However, with array_push() this example would create a two-dimensional array because PHP does not automatically flatten its arrays.



PHP Developer's Cookbook
PHP Developers Cookbook (2nd Edition)
ISBN: 0672323257
EAN: 2147483647
Year: 2000
Pages: 351

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net