AmitDiwan has Published 10744 Articles

PHP program to find the first ‘n’ numbers that are missing in an array

AmitDiwan

AmitDiwan

Updated on 17-Aug-2020 12:15:07

247 Views

To find the first ‘n’ numbers that are missing in an array, the PHP code is as follows −Example Live DemoOutputThe missing values of the array are 1 2 3 4 5In the above code, a function named ‘missing_values´ is defined, that takes the array, length, and the first few numbers ... Read More

PHP program to change the date format

AmitDiwan

AmitDiwan

Updated on 17-Aug-2020 12:10:00

188 Views

To change date format in PHP, the code is as follows −Example Live DemoOutput1970-01-01 00:00:00A function named ‘string_convert’ is used in PHP that takes a date as a parameter. The ‘strtotime’ function is used to convert English text timing into a UNIX timestamp −$sec = strtotime($my_date); $my_date = date("Y-m-d H:i", $sec); ... Read More

PHP program to find the minimum element in an array

AmitDiwan

AmitDiwan

Updated on 17-Aug-2020 12:04:08

2K+ Views

To find the minimum element in an array, the PHP code is as follows −Example Live DemoOutputThe lowest value of the array is 0A function named ‘get_min_value()’ takes an array as parameter. Inside this function, the count function is used to find the number of elements in the array, and it ... Read More

PHP program to delete an element from the array using the unset function

AmitDiwan

AmitDiwan

Updated on 17-Aug-2020 12:01:57

382 Views

To delete an element from the array using the unset function, the PHP code is as follows −Example Live DemoOutputAfter deleting the element, the array isArray (    [0] => Joe [1] => Ben [2] => Mary [3] => Barun [5] =>    Mona )Above, an array is defined, with multiple ... Read More

PHP program to find the length of the last word in the string

AmitDiwan

AmitDiwan

Updated on 17-Aug-2020 12:00:20

982 Views

To find the length of the last word in the string, the PHP code is as follows −Example Live DemoOutputThe length of the last word is 3 The length of the last word is 6A PHP function named ‘last_word_len’ is defined, that takes a string as the parameter −function last_word_len($my_string) { ... Read More

PHP program to find the first word of a sentence

AmitDiwan

AmitDiwan

Updated on 17-Aug-2020 11:57:19

816 Views

To find the first word of a sentence, the PHP code is as follows −Example Live DemoOutputThe first word of the string is HiA string is defined at first −$my_string = 'Hi there, this is a sample statement';The ‘strtok’ function is an in-built function that is used to split a string ... Read More

PHP program to find the number of characters in the string

AmitDiwan

AmitDiwan

Updated on 17-Aug-2020 11:55:55

982 Views

To find the number of characters in the string, the PHP code is as follows −Example Live DemoOutputThe number of characters in the string is 27Above, a string is defined that has more than the required spaces in between −$my_string = "Hi there, this is a sample ";Next, the length of ... Read More

PHP program to sum the digits in a number

AmitDiwan

AmitDiwan

Updated on 17-Aug-2020 11:54:11

4K+ Views

To sum the digits in a number, the PHP code is as follows −Example Live DemoOutputThe sum of digits is 11Above, a function named ‘sum_of_digits’ is defined, that takes an integer as a parameter.$my_num = "65";It first declares the variable sum as 0 and then iterates through the length of the ... Read More

PHP program to check if a string has a special character

AmitDiwan

AmitDiwan

Updated on 17-Aug-2020 11:31:47

8K+ Views

To check if a string has a special character, the PHP code is as follows;Example Live DemoOutputString has not been acceptedAbove, a function named ‘check_string’ is defined, that takes a string as its parameter −$my_string = 'This_is_$_sample!';Use regular expression to check if a string has a special character. If there is ... Read More

PHP program to replace a word with a different symbol in a sentence

AmitDiwan

AmitDiwan

Updated on 17-Aug-2020 11:25:33

219 Views

To replace a word with a different symbol in a sentence, the PHP code is as follows −Example Live DemoOutputThe final replaced string is : is a simple onlyHere, a string is defined, and the string that needs to be replaced with a different string is placed inside an array and ... Read More

Advertisements