Skip to content

Instantly share code, notes, and snippets.

@tanftw
Created June 4, 2015 16:53
Show Gist options
  • Save tanftw/0291d9455476e97b592a to your computer and use it in GitHub Desktop.
Save tanftw/0291d9455476e97b592a to your computer and use it in GitHub Desktop.
Array Symetry
<?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