<HTML ><HEAD ><TITLE >array_flip</TITLE ><META NAME="GENERATOR" CONTENT="Modular DocBook HTML Stylesheet Version 1.7"><LINK REL="HOME" TITLE="PHP Manual" HREF="index.html"><LINK REL="UP" TITLE="Array Functions" HREF="ref.array.html"><LINK REL="PREVIOUS" TITLE="array_filter" HREF="function.array-filter.html"><LINK REL="NEXT" TITLE="array_intersect_assoc" HREF="function.array-intersect-assoc.html"><META HTTP-EQUIV="Content-type" CONTENT="text/html; charset=ISO-8859-1"></HEAD ><BODY CLASS="refentry" BGCOLOR="#FFFFFF" TEXT="#000000" LINK="#0000FF" VLINK="#840084" ALINK="#0000FF" ><DIV CLASS="NAVHEADER" ><TABLE SUMMARY="Header navigation table" WIDTH="100%" BORDER="0" CELLPADDING="0" CELLSPACING="0" ><TR ><TH COLSPAN="3" ALIGN="center" >PHP Manual</TH ></TR ><TR ><TD WIDTH="10%" ALIGN="left" VALIGN="bottom" ><A HREF="function.array-filter.html" ACCESSKEY="P" >Prev</A ></TD ><TD WIDTH="80%" ALIGN="center" VALIGN="bottom" ></TD ><TD WIDTH="10%" ALIGN="right" VALIGN="bottom" ><A HREF="function.array-intersect-assoc.html" ACCESSKEY="N" >Next</A ></TD ></TR ></TABLE ><HR ALIGN="LEFT" WIDTH="100%"></DIV ><H1 ><A NAME="function.array-flip" ></A >array_flip</H1 ><DIV CLASS="refnamediv" ><A NAME="AEN7444" ></A ><P > (PHP 4 )</P >array_flip -- Exchanges all keys with their associated values in an array</DIV ><DIV CLASS="refsect1" ><A NAME="AEN7447" ></A ><H2 >Description</H2 >array <B CLASS="methodname" >array_flip</B > ( array trans)<BR ></BR ><P > <B CLASS="function" >array_flip()</B > returns an <A HREF="language.types.array.html" ><B CLASS="type" >array</B ></A > in flip order, i.e. keys from <TT CLASS="parameter" ><I >trans</I ></TT > become values and <TT CLASS="parameter" ><I >trans</I ></TT >'s values become keys. </P ><P > Note that the values of <TT CLASS="parameter" ><I >trans</I ></TT > need to be valid keys, i.e. they need to be either <A HREF="language.types.integer.html" ><B CLASS="type" >integer</B ></A > or <A HREF="language.types.string.html" ><B CLASS="type" >string</B ></A >. A warning will be emitted if a value has the wrong type, and the key/value pair in question <SPAN CLASS="emphasis" ><I CLASS="emphasis" >will not be flipped</I ></SPAN >. </P ><P > If a value has several occurrences, the latest key will be used as its values, and all others will be lost. </P ><P > <B CLASS="function" >array_flip()</B > returns <TT CLASS="constant" ><B >FALSE</B ></TT > if it fails. </P ><P > <TABLE WIDTH="100%" BORDER="0" CELLPADDING="0" CELLSPACING="0" CLASS="EXAMPLE" ><TR ><TD ><DIV CLASS="example" ><A NAME="AEN7470" ></A ><P ><B >Example 1. <B CLASS="function" >array_flip()</B > example</B ></P ><TABLE BORDER="0" BGCOLOR="#E0E0E0" CELLPADDING="5" ><TR ><TD ><PRE CLASS="php" >$trans = array_flip ($trans); $original = strtr ($str, $trans);</PRE ></TD ></TR ></TABLE ></DIV ></TD ></TR ></TABLE > </P ><P > <TABLE WIDTH="100%" BORDER="0" CELLPADDING="0" CELLSPACING="0" CLASS="EXAMPLE" ><TR ><TD ><DIV CLASS="example" ><A NAME="AEN7475" ></A ><P ><B >Example 2. <B CLASS="function" >array_flip()</B > example : collision</B ></P ><TABLE BORDER="0" BGCOLOR="#E0E0E0" CELLPADDING="5" ><TR ><TD ><PRE CLASS="php" >$trans = array ("a" => 1, "b" => 1, "c" => 2); $trans = array_flip ($trans); print_r($trans);</PRE ></TD ></TR ></TABLE ><P > now $trans is : <TABLE BORDER="0" BGCOLOR="#E0E0E0" CELLPADDING="5" ><TR ><TD ><PRE CLASS="screen" >Array ( [1] => b [2] => c )</PRE ></TD ></TR ></TABLE > </P ></DIV ></TD ></TR ></TABLE > </P ></DIV ><DIV CLASS="NAVFOOTER" ><HR ALIGN="LEFT" WIDTH="100%"><TABLE SUMMARY="Footer navigation table" WIDTH="100%" BORDER="0" CELLPADDING="0" CELLSPACING="0" ><TR ><TD WIDTH="33%" ALIGN="left" VALIGN="top" ><A HREF="function.array-filter.html" ACCESSKEY="P" >Prev</A ></TD ><TD WIDTH="34%" ALIGN="center" VALIGN="top" ><A HREF="index.html" ACCESSKEY="H" >Home</A ></TD ><TD WIDTH="33%" ALIGN="right" VALIGN="top" ><A HREF="function.array-intersect-assoc.html" ACCESSKEY="N" >Next</A ></TD ></TR ><TR ><TD WIDTH="33%" ALIGN="left" VALIGN="top" >array_filter</TD ><TD WIDTH="34%" ALIGN="center" VALIGN="top" ><A HREF="ref.array.html" ACCESSKEY="U" >Up</A ></TD ><TD WIDTH="33%" ALIGN="right" VALIGN="top" >array_intersect_assoc</TD ></TR ></TABLE ></DIV ></BODY ></HTML >