Array flip and reverse in php

Array flip and reverse in php

Flip and reverse sounds similar. Don’t mix-up them 🙂 array_flip function is useful when you only want to shift array index as array value and vice-verse. On the other hand if you want to change only array index in descending/reverse order then array_reverse function works great.

Array flip convert key in to index and index in to key.

$a = array (0 => "a", 1 => "b", 2=>"c");
print_r (array_flip ($a));
//output:  Array ( [a] => 0 [b] => 1

=> 2 )

Array reverse function change the order of array value.

$a = array (0 => "a", 1 => "b", 2=>"c");
print_r (array_reverse ($a));
//output: Array ( [0] => c [1] => b [2] => a )

- Useful Resource:

1. Associative Array syntax in php

2. 4 life savings php array function for web developers


Was this information useful? What other tips would you like to read about in the future? Share your comments, feedback and experiences with us by commenting below!

Share It

Related Posts