Web Technologies Lab Manual MCA II Year I Semester 2024 WEEK-3

Web Technologies Lab Manual MCA II Year I Semester 2024 

WEEK-3


Aim:

Write a PHP script to merge two arrays and sort them as numbers, in descending order

Source Code:

Week-3/Week3.php


<html>
<head>
    <title>Merge and sort two arrays in PHP</title>
</head>
<body>
<?php
    // creating arrays
    $f_array=array(6,9,0,8,1,2);
    $s_array=array(4,7,5,3);
    // to display array elements
    echo "Elements of First Array are : <br> ";
    for($i = 0;$i < count($f_array);$i++) {
        echo $f_array[$i]." ";
    }
    echo "<br>Elements ofSecond Array are : <br>";
    for($i = 0;$i < count($s_array);$i++) {
        echo $s_array[$i]." ";
    }
    // to merge two array elements
    $merge_array=array_merge($f_array,$s_array);

    echo "<br>Elements of merged array before sorting are :<br>";
    for($i = 0;$i < count($merge_array);$i++) {
        echo $merge_array[$i]." ";
    }
    // to srot the elements of the array in descending order.
    rsort($merge_array);

    echo "<br>Elements of merged array after sorting are :<br>";
    for($i = 0;$i < count($merge_array);$i++) {
        echo $merge_array[$i]." ";
    }
?>
</body>
</html>

Output:

image

 

No comments

File Uploading in PHP

  File Uploading in PHP PHP allow you to upload any type of a file i.e. image, binary or text files.etc..,PHP has one in built global variab...