<?php
// Test JSON handling for selected fees
echo "JSON Handling Test for Fee Selection\n";
echo "==================================\n";

// Test data
$selected_fees = [1, 2, 3, 4, 5];
echo "Original array: " . json_encode($selected_fees) . "\n";

// Encode and URL encode (simulating what happens in the select_fees.php page)
$selected_fees_json = json_encode($selected_fees);
$encoded_fees = urlencode($selected_fees_json);
echo "URL encoded JSON: $encoded_fees\n";

// Decode (simulating what happens in student_payment.php)
$decoded_fees = json_decode(urldecode($encoded_fees), true);
echo "Decoded array: " . json_encode($decoded_fees) . "\n";

// Verify it's still an array
if (is_array($decoded_fees)) {
    echo "✓ JSON handling works correctly\n";
} else {
    echo "✗ JSON handling failed\n";
}

// Test with empty array
$empty_fees = [];
$empty_fees_json = json_encode($empty_fees);
$encoded_empty = urlencode($empty_fees_json);
$decoded_empty = json_decode(urldecode($encoded_empty), true);

echo "\nEmpty array test:\n";
echo "Original: " . json_encode($empty_fees) . "\n";
echo "Decoded: " . json_encode($decoded_empty) . "\n";

if (is_array($decoded_empty)) {
    echo "✓ Empty array handling works correctly\n";
} else {
    echo "✗ Empty array handling failed\n";
}

echo "\nJSON handling test completed successfully!\n";
?>