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

VR23 Web Technologies Lab MCA II Year I Semester Experiment 7:

  Aim: PHP script to a) Find the length of a string. b) Count no of words in a string. c) Reverse a string. d) Search for a specific string....