Find this useful? Enter your email to receive occasional updates for securing PHP code.

Signing you up...

Thank you for signing up!

PHP Decode

<?php function mergeSort($arr) { $length = count($arr); if ($length <= 1)..

Decoded Output download

<?php 
function mergeSort($arr) { 
    $length = count($arr); 
     
    if ($length <= 1) { 
        return $arr; 
    } 
     
    $mid = (int) ($length / 2); 
    $left = array_slice($arr, 0, $mid); 
    $right = array_slice($arr, $mid); 
     
    $left = mergeSort($left); 
    $right = mergeSort($right); 
     
    return merge($left, $right); 
} 
 
function merge($left, $right) { 
    $result = []; 
    $leftLength = count($left); 
    $rightLength = count($right); 
    $leftIndex = $rightIndex = 0; 
     
    while ($leftIndex < $leftLength && $rightIndex < $rightLength) { 
        if ($left[$leftIndex] < $right[$rightIndex]) { 
            $result[] = $left[$leftIndex]; 
            $leftIndex++; 
        } else { 
            $result[] = $right[$rightIndex]; 
            $rightIndex++; 
        } 
    } 
     
    while ($leftIndex < $leftLength) { 
        $result[] = $left[$leftIndex]; 
        $leftIndex++; 
    } 
     
    while ($rightIndex < $rightLength) { 
        $result[] = $right[$rightIndex]; 
        $rightIndex++; 
    } 
     
    return $result; 
} 
 
// Contoh penggunaan 
$unsortedArray = [38, 27, 43, 3, 9, 82, 10]; 
$sortedArray = mergeSort($unsortedArray); 
 
echo "Array sebelum diurutkan: " . implode(", ", $unsortedArray) . "
"; 
echo "Array setelah diurutkan: " . implode(", ", $sortedArray) . "
"; 
 ?>

Did this file decode correctly?

Original Code

<?php
function mergeSort($arr) {
    $length = count($arr);
    
    if ($length <= 1) {
        return $arr;
    }
    
    $mid = (int) ($length / 2);
    $left = array_slice($arr, 0, $mid);
    $right = array_slice($arr, $mid);
    
    $left = mergeSort($left);
    $right = mergeSort($right);
    
    return merge($left, $right);
}

function merge($left, $right) {
    $result = [];
    $leftLength = count($left);
    $rightLength = count($right);
    $leftIndex = $rightIndex = 0;
    
    while ($leftIndex < $leftLength && $rightIndex < $rightLength) {
        if ($left[$leftIndex] < $right[$rightIndex]) {
            $result[] = $left[$leftIndex];
            $leftIndex++;
        } else {
            $result[] = $right[$rightIndex];
            $rightIndex++;
        }
    }
    
    while ($leftIndex < $leftLength) {
        $result[] = $left[$leftIndex];
        $leftIndex++;
    }
    
    while ($rightIndex < $rightLength) {
        $result[] = $right[$rightIndex];
        $rightIndex++;
    }
    
    return $result;
}

// Contoh penggunaan
$unsortedArray = [38, 27, 43, 3, 9, 82, 10];
$sortedArray = mergeSort($unsortedArray);

echo "Array sebelum diurutkan: " . implode(", ", $unsortedArray) . "\n";
echo "Array setelah diurutkan: " . implode(", ", $sortedArray) . "\n";

Function Calls

None

Variables

None

Stats

MD5 06c2b4d660e640435684bbf1771e3c26
Eval Count 0
Decode Time 67 ms