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

Output:

2. array_column ()

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

Output:

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.

Output:

4.array_diff ($ array1, $ array2)

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

Output:

5. array_reverse ()

Task: reverse array

Output:

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 php.net and lazy repair.
You can completely use the new syntax is “[]”.
Love!

Share the news now

Source : Viblo