PHP Classes

File: src/Functions/helpers.php

Recommend this page to a friend!
  Packages of Axel Pardemann   PHP Primitive Types Class   src/Functions/helpers.php   Download  
File: src/Functions/helpers.php
Role: Auxiliary script
Content type: text/plain
Description: Configuration script
Class: PHP Primitive Types Class
Manipulate PHP primitive value types as objects
Author: By
Last change:
Date: 9 months ago
Size: 719 bytes
 

Contents

Class file image Download
<?php

declare(strict_types=1);

namespace
NorseBlue\Prim\Functions;

/**
 * Merge the path segments to the base path.
 *
 * @param string $base
 * @param string|array<string> $segments
 * @param string $separator
 * @param bool $trailing_separator
 *
 * @return string
 */
function path_merge(
   
string $base,
   
$segments,
   
string $separator = DIRECTORY_SEPARATOR,
   
bool $trailing_separator = false
): string {
   
$path = rtrim($base, $separator);

    if (!
is_array($segments)) {
       
$segments = [$segments];
    }

    foreach (
$segments as $segment) {
       
$path .= $separator . $segment;
    }

   
$path = rtrim($path, $separator);

    return
$path . ($trailing_separator ? $separator : '');
}