paiza

<?php

$str1 = ('paiza');
$str2 = ('apple');
$str3 = ('letter');

function bigTower($str1, $str2, $str3)
{
    $str1 = trim($str1);
    $str2 = trim($str2);
    $str3 = trim($str3);

    $offset = false;
    for ($i = 0; $i < strlen($str1); $i++) {
        if (substr($str1, -($i + 1)) === substr($str2, 0, $i + 1)) {
            $offset = $i + 1;
        }
    }

    $str2 = $offset == true ? str_replace(substr($str2, 0, $offset), '', $str2) : $str2;
    $str = $str1 . $str2;

    $offset = false;
    for ($i = 0; $i < strlen($str2); $i++) {
        if (substr($str2, -($i + 1)) === substr($str3, 0, $i + 1)) {
            $offset = $i + 1;
        }
    }
    $str3 = $offset == true ? str_replace(substr($str3, 0, $offset), '', $str3) : $str3;
    $str .= $str3;
    return $str;
}

echo bigTower($str1, $str2, $str3);

猜你喜欢

转载自www.cnblogs.com/miosakura96/p/10327158.html