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 =>
<?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 =>
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 =>
Ans: Coding =>
<?php
$str="We Love To Eat Apple";
echo $str[0];
?>
Output Of The Coding =>
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 =>
<?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
Post a Comment