0% found this document useful (0 votes)
6 views

Array function program using Button

This document is an HTML program that implements various PHP array functions triggered by button clicks. It allows users to sort, reverse, count, search for an element, merge two arrays, and remove duplicates from an array. The results of these operations are displayed on the webpage after a button is pressed.

Uploaded by

thopteayush604
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
6 views

Array function program using Button

This document is an HTML program that implements various PHP array functions triggered by button clicks. It allows users to sort, reverse, count, search for an element, merge two arrays, and remove duplicates from an array. The results of these operations are displayed on the webpage after a button is pressed.

Uploaded by

thopteayush604
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 4

1. Array function program using Button.

<!DOCTYPE html>

<html>

<head>

<title>Array Functions in PHP</title>

</head>

<body>

<h2>PHP Array Function Operations</h2>

<?php

$array1 = array(1,2,3,4,5,6,3,6,1);

$array2 = array("Apple", "Banana", "Cherry");

function displayArray($array)

return implode(", ", $array);

if ($_SERVER["REQUEST_METHOD"] == "POST")

$action = $_POST["action"];

echo "<h3>Result:</h3>";

switch ($action)

{
case "sort":

sort($array1);

echo "<b>Sorted Array:</b> " . displayArray($array1);

break;

case "reverse":

$reversed = array_reverse($array1);

echo "<b>Reversed Array:</b> " .


displayArray($reversed);

break;

case "count":

echo "<b>Array Length:</b> " . count($array1);

break;

case "search":

$searchElement = 4;

if (in_array($searchElement, $array1))

echo "<b>Element $searchElement found in the


array!</b>";

else

echo "<b>Element $searchElement not found.</b>";

break;
case "merge":

$mergedArray = array_merge($array1, $array2);

echo "<b>Merged Array:</b> " .


displayArray($mergedArray);

break;

case "unique":

$uniqueArray = array_unique($array1);

echo "<b>Array with Unique Values:</b> " .


displayArray($uniqueArray);

break;

?>

<!-- Buttons to trigger array functions -->

<form method="post">

<button type="submit" name="action" value="sort">Sort Array</button>

<button type="submit" name="action" value="reverse">Reverse Array</button>

<button type="submit" name="action" value="count">Array Length</button>

<button type="submit" name="action" value="search">Search Element(4)</button>

<button type="submit" name="action" value="merge">Merge Arrays</button>

<button type="submit" name="action" value="unique">RemoveDuplicates</button>

</form>

</body>

</html>

OUTPUT:

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy