Revision Difference
table.Flip#551408
<function name="Flip" parent="table" type="libraryfunc">⤶
<description>⤶
Flips key-value pairs of each element within a table, so that each value becomes the key, and each key becomes the value.⤶
⤶
<warning>Take care when using this function, as a Lua table cannot contain multiple instances of the same key. As such, data loss is possible when using this function on tables with duplicate values.⤶
⤶
```⤶
local test = { test = 1, test2 = 1 }⤶
local f = table.Flip( test )⤶
PrintTable( f )⤶
-- Outputs "1 = test2"⤶
```⤶
</warning>⤶
</description>⤶
<realm>Shared and Menu</realm>⤶
<args>⤶
<arg name="input" type="table">The table to flip items of.</arg>⤶
</args>⤶
<rets>⤶
<ret name="" type="table">The flipped table.</ret>⤶
</rets>⤶
<added>2023.08.08</added>⤶
</function>⤶
⤶
<example>⤶
<code>⤶
local productIngredients = { "Cocoa Mass", "Cocoa Butter", "Vanilla", "Cocoa Solids: 70% min" }⤶
⤶
local flipped = table.Flip( productIngredients )⤶
⤶
PrintTable( flipped )⤶
</code>⤶
<output>⤶
```⤶
Cocoa Butter = 2⤶
Cocoa Mass = 1⤶
Cocoa Solids: 70% min = 4⤶
Vanilla = 3⤶
```⤶
</output>⤶
⤶
</example>