Home > Articles


  • Print
  • + Share This

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.


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)


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.

  • + Share This
  • 🔖 Save To Your Account

Related Resources

There are currently no related titles. Please check back later.