Created
June 4, 2015 16:53
-
-
Save tanftw/0291d9455476e97b592a to your computer and use it in GitHub Desktop.
Array Symetry
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Put an array. Then make the key same as value. Or key will become slug of value of slug is set to true | |
* | |
* @param Array $array Array to convert | |
* @param boolean $slug Slug the key or not | |
* @return Array output | |
*/ | |
function array_symmetry( $array, $slug = false ) | |
{ | |
$output = array(); | |
foreach ( (array) $array as $key => $value ) | |
{ | |
$output_key = $slug ? str_snake( $value ) : $value; | |
$output[$output_key] = $value; | |
} | |
return $output; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment