Skip to content

Instantly share code, notes, and snippets.

@Radon8472
Last active July 8, 2020 08:17
Show Gist options
  • Save Radon8472/b0129da607efc8a2228b4517cfce3f01 to your computer and use it in GitHub Desktop.
Save Radon8472/b0129da607efc8a2228b4517cfce3f01 to your computer and use it in GitHub Desktop.
php helper functions (to ensure version compatibility)
<?php
/**
* Helper function to avoid problems with the switches argument order of implode since php 7.4.0
*
* @see: https://www.php.net/manual/function.implode.php
* @see: https://3v4l.org/MZRZA
*
* @param String $glue
* @param array $pieces
*
* @return string
*/
protected static function implode($glue, $pieces) {
if(func_num_args() == 1) {
$pieces = $glue;
$glue = "";
}
return (version_compare(PHP_VERSION, '7.4.0') >= 0)
? implode($glue,$pieces)
: implode($pieces,$glue);
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment