PHP array_flip() function
In this chapter you will learn:
- Definition for PHP array_flip() function
- Syntax for PHP array_flip() function
- Parameter for PHP array_flip() function
- Return value from PHP array_flip() function
- Example - Flip an associate array
Definition
The array_flip()
function takes an array as its parameter, and exchanges all the keys
in that array with their values, returning the new, flipped array.
Syntax
PHP array_flip() function has the following syntax.
array array_flip ( array arr )
Parameter
Parameter | Is Required | Description |
---|---|---|
arr | Required. | Array to flip |
Return
PHP array_flip() function returns the new, flipped array
Example
<?PHP/* j av a2s .c o m*/
$capitalcities['A'] = 'apple';
$capitalcities['B'] = 'better';
$capitalcities['W'] = 'java2s.com';
$flippedcities = array_flip($capitalcities);
var_dump($flippedcities);
$a2=array("d"=>"D","b"=>"B","e"=>"E","j"=>"java2s.com");
$a2 = array_flip($a2);
var_dump($a2);
?>
The code above generates the following result.
Next chapter...
What you will learn in the next chapter:
- Definition for PHP array_intersect() Function
- Syntax for PHP array_intersect() Function
- Parameter for PHP array_intersect() Function
- Example - Merge indexed array
- Example - merge keys during intersect
Home » PHP Tutorial » PHP Array Functions