Assignment For Improvement-IWP

You might also like

Download as pdf or txt
Download as pdf or txt
You are on page 1of 5

Assignment for Improvement-IWP

18BCE0557 KUSHAL

1. Display the months of the year using associative arrays in the following format “January is the
First month” and so on for all the months.

<?php
$months​ = ​array​(​"First"​=>​"January"​, ​"Second"​=>​"February"​,
"Third"​=>​"March"​, ​"Fourth"​=>​"April"​, ​"Fifth"​=> ​"May"​, ​"Sixth"​=>​"June"​,
"Seventh"​=> ​"July"​, "
​ Eighth"​=>​"August"​, ​"Ninth"​=>​"September"​,
"Tenth"​=>​"October"​, "​ Eleventh"​=>​"November"​, ​"Twelfth"​=>​"December"​);

​ <center>"​;
echo​ "
echo​ "​ </br></br></br></br>"​;
foreach​(​$months​ as ​$order​ => ​$month​) {
​echo​ ​"<b>"​. ​$month​ .​" is the "​. ​$order​ .​" month </b>"​;
​echo​ ​"</br></br>"​;
}
echo​ ​"</center>"​;

?>

2. Use the inbuilt string functions

a) Display only the unique characters present in the string “I like PHP and MySQL!”

b) Convert the given string into an array. $str=”Red#Blue#Yellow#Green”

c) In the string “Hello Class! It is an interesting class”, replace class with “world” irrespective of the
case.

d) Count the number of times “over” is occurs in the string “Over the hills and over the mountains..
over and over again they went”.

e) Randomly shuffle the letters in the string

a)

<?php

$string1​ = ​"I like PHP and MySQL!"​;


echo​ ​count_chars​(​$string1​, ​3​)

?>
b)

<?php
$str​=​"Red#Blue#Yellow#Green"​;
print_r​ (​explode​(​"#"​, ​$str​));
?>

c)

<?php
$str1​ = ​"Hello Class! It is an interesting class"​;
echo​ ​str_ireplace​(​"class"​,​"world"​,​$str1​);
?>

d)
<?php
$str​ = ​"Over the hills and over the mountains.. over and over again they
went"​;

// Considering it as not case sensitive

echo​ ​substr_count​(​strtolower​(​$str​), ​"over"​)

?>

e)
<?php

​ Doing DA before many days of deadline is so much pleasurable, wish


$str​ = "
I knew this earlier!"​;

echo​ ​"Original String: "​. ​$str​;

echo​ ​"</br></br>"​;

echo​ ​"Shuffled String: "​. ​str_shuffle​(​$str​);

?>

You might also like