★ wanayoo — archive 1999 http://www.php.net/manual/ja/function.array-flip.phpNouvelle recherche | Portail wanayoo

PHP Home Page

Manual Table of Contents
Up to Arrays
Quick Reference
English version of this pageGerman version of this pageItalian version of this pageFrench version of this pageHungarian version of this page
Arrays
* array
* array_count_values
* array_diff
* array_flip
* array_intersect
* array_keys
* array_merge
* array_merge_recursive
* array_multisort
* array_pad
* array_pop
* array_push
* array_rand
* array_reverse
* array_shift
* array_slice
* array_splice
* array_unshift
* array_values
* array_walk
* arsort
* asort
* compact
* count
* current
* each
* end
* extract
* in_array
* key
* krsort
* ksort
* list
* next
* pos
* prev
* range
* reset
* rsort
* shuffle
* sizeof
* sort
* uasort
* uksort
* usort
Manual: array_flip
View the source code for this pageSearch the site



Previous page
 array_diff
 Updated
Sat, 12 Aug 2000
array_intersect 
Next page


array_flip

(PHP4 >= 4.0b4)

array_flip -- 配列の値を逆順にする

説明

array array_flip (array trans)

array_flip() は、配列を逆順にして返します。

例 1. array_flip()の例


$trans = array_flip ($trans);
$original = strtr ($str, $trans);
      

注意: この関数は、PHP 4.0で追加されました。


User Contributed Notes: array_flip


rlynch@ignitionstate.com
27-Jan-2000 12:53
'flip' may be very specific to a Perl hacker or something, but to us mere mortals this is an undefined term...
PHP4.0b3 doesn't have it yet, so I can't find out what it does easily and post it here. Sorry.
I thought it would be 'reverse', but there's an array_reverse, so...
Guess: Flip all the keys/values? What if the value isn't a valid key?



vwagner@tetondata.com
28-Feb-2000 01:58
I concur with the above. What the heck is "flip" order???


rasmus@php.net
16-Mar-2000 07:37
eg. $a[0]="abc"; $a[1]="def";
After an array_flip() you get:
$a["abc"]=0; $a["def"]=1;



tworks@troutworks.com
17-May-2000 02:06
One hackish but slick use of array_flip() is to reduce an array to only its unique values. An example:

<PRE>
&lt;?php
$a[0] = "Tom";
$a[1] = "Tom";
$a[2] = "Dick";
$a[3] = "Dick";
$a[4] = "Harry";
$trans = array_flip($a);
$a = array_flip($trans);
?>
</PRE>

Since array offsets must be unique, duplicates will be blown away. Is that too ugly?



monte@ispi.net
17-May-2000 11:57
Maybe a more appropriate name would be array_transpose. Think of it as a matrix.


monte@ispi.net
18-May-2000 12:01
Question: what if the values are arrays themselves? Then what happens when you "flip"?


jmayer@cobalt.com
13-Jul-2000 09:08
To uniquify a list, this is better
<pre>
$hash = array_flip($array);
$array = array_keys($hash);
</pre>
Otherwise: If you just do two array_flip operations, you end up with a sparse array (the elements in the old arrays that were duplicates are left as gaps).



 About Notes


Previous page
 array_diff
 Updated
Sat, 12 Aug 2000
array_intersect 
Next page





Who's responsible for this?
Top of this page

Site
Hosting:



Located in
United States
Elements of this website are subject to copyright.
Questions about installing or using PHP should be directed to one of the mailing lists.
Only questions about the website should be directed to webmaster@php.net.