Programmings Based On Array And String Functions Including Printing The Array Using Echo, Finding Out The 1st And Last Word In A Sentence, Finding Out The 1st Alphabet From A String And Also To Check Whether My Variable Is In Form Of Array Or Not

Programmings Based On Array And String Functions Including Printing The Array Using Echo Where We Cannot Concatenate The Index Number, Finding Out The 1st And Last Word In A Sentence, Finding Out The 1st Alphabet From A String And Also To Check Whether My Variable Is In Form Of Array Or Not

Q1. Print the array using echo where ou cannot concatinate the index number.

Ans: Coding Example No. - 01 =>

<?php
$arr=["500","1000","1500","2000"];
$len=count($arr);
for ($i=0; $i < $len; $i++) {
    echo "$arr[$i]";
}
?>

<?php
$arr=["500","1000","1500","2000"];
$len=count($arr);
for ($i=0; $i < $len; $i++) {
    echo "$arr[$i]"."<br>";
}
?>

Output Of The Coding Example No. - 01 =>



Coding Example No. - 02 =>

<?php
$arrayName = array('100','200','300','400','500');
$length=count($arrayName);
for ($j=0; $j < $length; $j++) {
    echo "$arrayName[$j]";
}
?>

<?php
$arrayName = array('100','200','300','400','500');
$length=count($arrayName);
for ($j=0; $j < $length; $j++) {
    echo "$arrayName[$j]"."<br>";
}
?>

Output Of The Coding Example No. - 02 =>



Q2. Take a sentence "Today is Tuesday". Find the 1st and last word in the sentence.

Ans: Coding =>

<?php
$str="Today is Tuesday";
$exp=explode(" ", $str);
$firstword=array_shift($exp);
$lastword=array_pop($exp);
echo "The 1st word in the sentence is: ".$firstword."<br>";
echo "The last word in the sentence is: ".$lastword;
?>

Output Of The Coding =>


Q3. Take a string "We Love To Eat Apple" - Find out the 1st alphabet.

Ans: Coding =>

<?php
$str="We Love To Eat Apple";
echo $str[0];
?>

Output Of The Coding =>


Q4. Check your variable is in the form of array or not.

Ans: Coding Example No. - 01 =>

<?php
$arrayName = array('Name' => 'Ayan Bhattacharjee', 'Age' => '28');
if (is_array($arrayName)) {
    echo "It's in the form of array";
}
else{
    echo "It's not in the form of array";
}
?>

Output Of The Coding Example No. - 01 =>


Coding Example No. - 02 =>

<?php
$arr=["50","100","150"];
if (is_array($arr)) {
    echo "It's in the form of array";
}
else{
    echo "It's not in the form of array";
}
?>

Output Of The Coding Example No. - 02 =>




 

Comments

Popular posts from this blog

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

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