Untitled
unknown
plain_text
7 months ago
1.8 kB
6
Indexable
<html>
<head>
<title>PHP Array Manipulation</title>
<style>
form{
width:20%;
height:30%;
background-color:#00ffff;
border-radius:8px;
border:1px solid;
}
hr{
border-color:#ff0000;
}
</style>
</head>
<body bgcolor="skyblue">
<center>
<h1> <u>PHP Array Manipulation Function</u></h1>
<form method="POST">
<label for="courses">Enter courses(comma-separation):</label><br><BR>
<input type="text" id="courses" name="courses" placeholder="e.g. BCA ,BBA,BCOM,MCA" required><br><br>
<input type="submit" name="submit" value="submit">
</form>
<?php
if(isset($_POST['submit'])){
$courses=explode(",", $_POST['courses']);
echo"<h3>original array:</h3>";
foreach($courses as $course){
echo $course."<br>";
}
echo"<hr>";
echo"length of the array is:".count($courses);
echo"<hr>";
echo"sorted array is follows:<br>";
sort($courses);
foreach($courses as $course){
echo $course."<br>";
}
echo"<hr>";
echo"reversed array is as follows:<br>";
$reversedCourses=array_reverse($courses);
foreach($reversedCourses as $course){
echo $course."<br>";
}
echo"<hr>";
echo"searching for 'BE' in he given array:<br>";
$search=array_search('BE',$courses);
if($search!==false){
echo"'BE' found at index $search.<br>";
}else{
echo"'BE' not found.<br>";
}
echo"<hr>";
echo"array intersection(with predefined array):<br>";
$name=array('BCA','BBA','MCA','BA','BCOM');
$intersection=array_intersect($courses,$name);
foreach($intersection as $course){
echo $course."<br>";
}
echo"<hr>";
echo"array merge:<br>";
$merged=array_merge($courses,$name);
foreach($merged as $course){
echo $course."<br>";
}
echo"<hr>";
echo"removing duplicate elements from merged array:<br>";
$unique=array_unique($merged);
foreach($unique as $course){
echo $course."<br>";
}
}
?>
</center>
</body>
</html>
Editor is loading...
Leave a Comment