arro

 <?php

// Indexed Array
$indexedArray = array(5, 3, 8, 1, 9);
echo "Original Indexed Array: ";
print_r($indexedArray);
echo "<br>";
// Sorting Indexed Array
sort($indexedArray); // Sort in ascending order
echo "\n\nIndexed Array after sort(): ";
print_r($indexedArray);
echo "<br>";
rsort($indexedArray); // Sort in descending order
echo "\n\nIndexed Array after rsort(): ";
print_r($indexedArray);
echo "<br>";
// Associative Array
$associativeArray = array(
    "John" => 25,
    "Alice" => 30,
    "Bob" => 20,
    "Diana" => 35
);
echo "\n\nOriginal Associative Array: ";
print_r($associativeArray);

// Sorting Associative Array
asort($associativeArray); // Sort by values in ascending order, preserving keys
echo "\n\nAssociative Array after asort(): ";
print_r($associativeArray);

ksort($associativeArray); // Sort by keys in ascending order
echo "\n\nAssociative Array after ksort(): ";
print_r($associativeArray);

arsort($associativeArray); // Sort by values in descending order, preserving keys
echo "\n\nAssociative Array after arsort(): ";
print_r($associativeArray);

krsort($associativeArray); // Sort by keys in descending order
echo "\n\nAssociative Array after krsort(): ";
print_r($associativeArray);
?>

Comments

Popular posts from this blog

Privacy Policy – Kisan Hisab App

GST Hisab

Privacy Policy - QRMaker