PHP Array flip() Function
Last Updated : 17 Mar 2025
This function is used to flip the array with the keys and values. It takes one parameter that is an array. The returned array will contain the flipped elements. The values will be the keys, and the keys will be the values. This function was introduced in PHP 4.0.
Syntax
Parameter
| Parameter | Description | Is compulsory |
|---|---|---|
| array | Specifies an array of key/value pairs to be flipped. | compulsory |
Return Type
It returns the flipped array on success.
Note:The values of the array need to be valid keys, i.e., they need to be either integer or string.
EXAMPLE 1
Output:
Array ( [1] => a [2] => b [3] => c [4] => d [5] => e )
EXAMPLE 2
Output:
Array ( [oranges] => 0 [apples] => 1 [banana] => 2 )
EXAMPLE 3
Output:
Array ( [jaya] => amitabh [nargis] => raj [katrina] => akshay [juhi] => aamir )
EXAMPLE 4
Output:
Array ( [brown] => a [green] => b [yellow] => c )
Next TopicPhp-in-array-function