Untitled
unknown
plain_text
a month ago
2.1 kB
3
Indexable
<html> <head> <title>PHP array manipulation</title> <style> body{ border:2px solid black; height:auto; width:500px; margin-left:500px; } </style> </head> <body> <center> <h1>PHP array manipulatiopn Function</h1> <form method="POST"> <lable for="courses">Enter Courses(comma-separted):</lable> <br> <input type="text" id="courses" name="courses" placeholder="e.g. BCA,BBA, BCOM, MCA" requried><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 "Lenght of the array is: ".count($courses); echo"<hr>"; echo"sorted array is as follows: <br>"; sort($courses); foreach($courses as $course){ echo $course."<br>"; } echo "<hr>"; echo "reversed array is as folows: <br>"; $reversedCourses= array_reverse($courses); foreach($reversedCourses as $course){ echo $course."<br>"; } echo"<hr>"; echo"Searching for 'BCA' in the given array:<br>"; $search= array_search('BCA',$courses); if($search!=false){ echo"'BCA' found at index $search.<br>"; }else{ echo"'BCA' not found <br>"; } echo"<br>"; echo"Array intersction (with predefined array):<br>"; $name=array('BCA','BBA','MCA','BA'); $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 element form merged array: <br>"; $unique=array_unique($merged); foreach($unique as $course){ echo$course."<br>"; } } ?> </center> </body> </html>
Editor is loading...
Leave a Comment