Several functions are useful when working with Array in PHP

Tram Ho

[MEMO] Some functions are quite useful when working with Array in PHP

Recently, I did a PHP project. And I find PHP’s Array quite interesting, it feels very flexible and PHP also supports a lot of functions to work with Array is really very powerful. In this article I would like to memo those functions. The main purpose is memo, after forgetting to review.
And you, if you see any good function, just add me a comment.
Let’s go!

1. array_unique ()

This function is responsible for removing duplicate elements and returning an array containing unique elements


2. array_column ()

Task: pick up the values ​​of an array_key from a nested array and return a new array.


3. array_flip ()

Task: reverse the positions of keys and values ​​in arrays. The value it returns is 1 Array reversed between key and value.


4.array_diff ($ array1, $ array2)

Task: Find out which elements are in array1 that aren’t in the rest of the arrays.


5. array_reverse ()

Task: reverse array


There are many other interesting content, the more likely you can join here Well, my array declaration syntax using the old syntax, by copying from and lazy repair.
You can completely use the new syntax is “[]”.

Share the news now

Source : Viblo