Last active
December 12, 2019 10:03
-
-
Save AucT/55340f911259fd7a6e9a76b766985c6c to your computer and use it in GitHub Desktop.
decompact - replace php compact with array
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 decompact(...$params) | |
{ | |
$minimumParamsForNewLines = 4; | |
$newLine = "\n"; | |
if (count($params) < $minimumParamsForNewLines) { | |
$newLine = ''; | |
} | |
echo "[{$newLine}"; | |
foreach ($params as $i=>$param) { | |
$comma = ","; | |
if ($i === count($params) - 1) { | |
$comma = ''; | |
} | |
echo "'{$param}' => \${$param}{$comma}{$newLine}"; | |
} | |
echo "]{$newLine}"; | |
} | |
decompact('var1', 'var2', 'var3'); | |
decompact('var1', 'var2', 'var3', 'var4'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment