Untitled

mail@pastecode.io avatar
unknown
php
2 years ago
312 B
1
Indexable
Never
<?php

function reverse(string $str) {
    $first = 0;
    $last = strlen($str) - 1;
    while ($first < $last) {
        $tmpFirst = $str[$first];
        $str[$first] = $str[$last];
        $str[$last] = $tmpFirst;
        $first++;
        $last--;
    }
    
    return $str;
}

echo reverse('abc'), PHP_EOL;