Programmings Based On Array And String Functions To Merge The 2 Arrays, Then After Merge Convert Into String And Then Find Out The 1st And Last Word From The Reverse String

 Programmings Based On Array And String Functions To Merge The 2 Arrays, Then After Merge Convert Into String And Then Find Out The 1st And Last Word From The Reverse String

Q1. Take 2 arrays then margin the arrays. After margin convert into string then reverse the string and find out 1st and last word from the reverse string.

Ans: Coding =>

<?php
$arr1=["Dhoni","Rohit","Kohli","Rahul"];
$arr2=["Bumrah","Shami","Siraj","Chahal"];
$arrmer=array_merge($arr1,$arr2);
print_r($arrmer);
echo "<br>";
$str=implode(" ", $arrmer);
print_r($str);
echo "<br>";
$strrev=strrev($str);
print_r($strrev);
echo "<br>";
$arr=explode(" ", $strrev);
print_r($arr);
echo "<br>";
$firstword=array_shift($arr);
$lastword=array_pop($arr);
print_r($firstword);
echo "<br>";
print_r($lastword);
?>

Output Of The Coding =>


Explanation Of The Coding =>

Here my first output in the output page is of array merge where I have taken two arrays one is $arr1 and another is $arr2 and then I have merged this two arrays using array_merge() function.

                                        Then my second output is in string where I have convert the array merge i.e. $arrmer into string by using implode() function.

                                                           Then my third output is of reverse string after converting the array into string I have reversed the string by using strrev() function.

                                                                                       Then my fourth output is of array that is to find the first and last word from the string I need to first convert the string into array using explode() function, which I have done in my fourth step.

                    Then my fifth output is of first word where I have finded out the first word from the reverse string using by array_shift() function.

                                               Then my sixth output is of last word where I have finded out the last word from the reverse string by using array_pop() function.












Comments

Popular posts from this blog

PHP WEB DEVELOPMENT INTERVIEW QUESTIONS ASKED IN APOLLO HOSPITAL ALONG WITH MY OWN CONCEPTS AND MY OWN EXPLANATION ANSWERS(PART - 1) REST OF THE QUESTIONS AND ANSWERS WILL BE PREPARED BY ME IN MY NEXT BLOG

Mini Project On Multi User CRUD Operations(Create, Read, Update & Delete) Of Donar Details Of Indian Nationals Who Donate To Ramkrishna Math, Belur Math Using PDO (PHP Data Objects) With Proper Explanation Of Each And Every Individual Line Of The Code Of connection.php Page, form.php Page, formaction.php Page, admin_display.php Page, client_display.php Page, edit.php Page, editaction.php Page And delet.php Page (Here You Will Find The Image Of Sayang Sri Ramkrishna Dev, Sayang Sri Ma Sarada Devi & Sayang Sri Swami Vivekananda) In My CRUD Operation