Error Handling in PHP
programmingdive
by Admin
4y ago
                 A programming language comprises a set of instructions that produce different types of output. Different programming languages have different ways of executing these instructions but programs are mainly executed at two levels e.g. compile time and run time. When instructions are executed and something bad happened then at that time either of the two types of error occurred. Compile Time Error Run Time Error     Without fixing these errors program will behave incorrectly. Contents ..read more
Visit website
Deleting an element from an array in PHP
programmingdive
by Admin
4y ago
There are different ways to delete an array element. 1. Using unset() function - To delete an element from an array, PHP has provided an inbuilt function (unset()) to destroy it. Syntax: unset ( mixed $var [, mixed $... ] ) : void Parameters:- mixed $var - It takes variable as a parameter which can be anything e.g., $var, $arr[$key]. We can provide as many variables as possible. So, let's understand the use of unset() using an example- <?php$name = 'Mogan Fox';// destroy variableunset($name);echo $name; // output Notice: Undefined variable: x in sample.php on line 12 So, this w ..read more
Visit website
How to convert first character of every word into uppercase?
programmingdive
by Admin
4y ago
 In our day-to-day project task, we may ask to get the string from a database or from the user and by using this string we need to process it as per the requirement. There may be a situation when we may get all the words in the string as uppercase e.g., user's name, address, etc. For example: Name : MEGAN FOX Address: IMPRINT PR NEUEHOUSE, 6121 SUNSET BLVD., LOS ANGELES, CA 90028, USA But in the database, we store both the strings as lowercase keeping the first character of each word as uppercase. In this situation, we need a short but sweet solution to meet the string requiremen ..read more
Visit website
How to check if a string contains a specific word?
programmingdive
by Admin
4y ago
To check if a particular/specific word is present in the given string or not, PHP has provided an inbuilt strpos() function. Syntax:- strpos ( string $haystack , mixed $needle [, int $offset = 0 ] ) : int Where, string $haystack - is the actual string to search in. (strictly string data type) | required mixed $needle - is the string that needs to find in the string | required int $offsest - when specified, the search of the needle in the string will start from that index  | Optional Return - FALSE if the needle was not found otherwise TRUE. Let's use strpos() to get the clear idea ..read more
Visit website
Write a PHP function which takes a string as input and returns the length and frequency of each word in the string in an HTML table?
programmingdive
by Admin
4y ago
To find number of duplicate occurrence of the word in the string, we need to first loop through each word of the string, save it independently in an array and then if duplicate word is found then we need to increase the current count of the word value. Let's first jump right into the example and then we will understand- <?phpfunction get_number_of_duplicate_word_count($str){ $arr = array(); $exp = explode(' ', preg_replace('/\s+/', ' ', $str)); $nm_of_words = count($exp); $html = '<table ><tr><th>word</th><th>count</th&g ..read more
Visit website
How to write a function to reverse a given string without using string reversal functions in PHP?
programmingdive
by Admin
4y ago
To reverse a string without using PHPs inbuilt string function, we have different options. So the first option is instead of using inbuilt function we can use different required functions like strlen(). So, why strlen()? Because to reverse a given string without using string reversal functions in PHP, first thing that comes into mind is that how many characters are there in the string? PHP has provided solution over this to count a number of characters present in the string and the solution is using strlen(). Let's jump right into the first of the many solutions over the question. $sting ..read more
Visit website
Write a program in PHP to find the sum of first 20 even number?
programmingdive
by Admin
4y ago
To get the sum of the first 20 even numbers, we need to first understand what is even number. Let's understand is what is even number? Even number is any integer that can be divided exactly by 2. So, Let's understand the meaning of it using an example- $x = 2;if($x % 2 ==0) { echo 'This is even number';} OR $x = 4;if($x%2 == 0) { echo 'This is even number';} and so on. So basically, all the numbers which are multiples of 2 are even numbers here. Now, let's jump into the question to find out the first 20 even numbers. function get_sum($nm) { $sum = 0; $curr_even_nm = 2 ..read more
Visit website
PHP Method Chaining
programmingdive
by Admin
4y ago
One of the major changes between PHP4 and PHP5 is that in PHP5 method can return objects. As the name indicates, method chaining is nothing but executing multiple methods in a single call. This means in regular method calling we write code as follows- class studentDetails { public $id = 0; public $name = ''; public $address =''; public function setStudentId($id) { $this->id = $id; } public function setStudentName($name) { $this->name = $name; } public function setStudentAddress($address) { $this->address = $address; }}$obj = new studentDetails();$obj->setStudentId(1);$obj-> ..read more
Visit website
Autoload in php
programmingdive
by Admin
4y ago
When we work on a small project then we include all the related files in the main configuration file. But as the project grows then it becomes tedious to include individually. This process of addition happens by using include/require statement. In the world of PHP, we have two main options to start a project. Either via core PHP or via PHP Framework. If we planned to use PHP Framework (like CodeIgniter, Symfony, Laravel) then we do not need to worry about including files manually. There are framework based ways to add files OR there is a composer to add PHP dependencies and include all such ..read more
Visit website
PHP Interview Questions and Answers
programmingdive
by Admin
4y ago
PHP Interview Questions and Answers:        Following are the list of questions that are generally asked in the interview questions. These contain basic as well as advanced level PHP interview questions. Here we will try to cover as much as possible.        For PHP coding interview questions you can check this link.        Let's begin with it. 1. What is PHP and who invented it? Answer:                 PHP stands for PHP Hypertext Preprocessor. It is an open-s ..read more
Visit website

Follow programmingdive on FeedSpot

Continue with Google
Continue with Apple
OR