Last active
August 29, 2018 07:43
-
-
Save Caffe1neAdd1ct/34636c6521f2efe3f537cf5d92448acf to your computer and use it in GitHub Desktop.
Splitting get parameters by two delimiters
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 | |
function getParamSplitBy($param, $delimiter='~', $subDelimiter=':') | |
{ | |
$paramChunks = array_chunk(preg_split('/('.$delimiter.'|'.$subDelimiter.')/', urldecode($this->getParam($param))), 2); | |
$keys = array_column($paramChunks, 0); | |
$unpaddedValues = array_column($paramChunks, 1); | |
$keyCount = count($keys); | |
$unpaddedCount = count($unpaddedValues); | |
$values = ($keyCount > count($unpaddedCount)) ? | |
array_pad($unpaddedValues, $keyCount, '') : | |
$unpaddedValues; | |
$paramPairs = array_combine($keys, $values); | |
return $paramPairs; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment