Curriculum
Course: PHP Basic
Login

Curriculum

PHP Basic

PHP Install

0/1

PHP Casting

0/1

PHP Constants

0/1

PHP Magic Constants

0/1

PHP Operators

0/1

PHP Reference

0/276
Text lesson

array_flip()

Example

Swap all keys with their corresponding values in an array.

<?php
$a1=array(“a”=>“red”,“b”=>“green”,“c”=>“blue”,“d”=>“yellow”);
$result=array_flip($a1);
print_r($result);
?>

Definition and Usage

The array_flip() function swaps all keys with their corresponding values in an array.

Syntax

array_flip(array)

Parameter Values

Parameter

Description

array

Required. Specifies an array of key-value pairs to be swapped.

Technical Details

Return Value:

Returns the flipped array on success, or NULL on failure.

PHP Version:

4+