Core Function Flip
From Sputnik Wiki
(Difference between revisions)
(Created page with "<pre> Flip( <array> ) </pre> === Description === Exchanges all keys with their associated values in an array === Parameters === ==== array ==== The array to use. === Return...") |
m (1 revision) |
||
(2 intermediate revisions by one user not shown) | |||
Line 35: | Line 35: | ||
printr $array; | printr $array; | ||
− | $array = flip | + | $array = flip $array; |
echo "After flip:\n"; | echo "After flip:\n"; |
Latest revision as of 12:37, 14 June 2015
Flip( <array> )
Contents |
Description
Exchanges all keys with their associated values in an array
Parameters
array
The array to use.
Return Value
Success: Returns new array.
Failure: Returns 0.
Remarks
Returns an array in flip order, i.e. keys from trans become values and values from trans become keys.
Note that the values of need to be valid keys, i.e. they need to be either integer or string.
If a value has the wrong type the key/value pair in question will not be included in the result.
Example
$array = array( "Cat" => "Meow", "Dog" => "Woof", "Cow" => "Moo" ); echo "Before flip:\n"; printr $array; $array = flip $array; echo "After flip:\n"; printr $array;