Unset() function means in php?

php-training-in-gurgaon
The behavior of unset()  inside of a function can vary depending on what type of variable you are attempting to destroy. If a globalized variable is unset() inside of a function, only the local variable is destroyed. The variable in the calling environment will retain the same value as before unset()  was called. Example <?php function destroy_foo() { global $foo; unset($foo); } $foo = 'bar'; destroy_foo(); echo $foo; ?>
Read More

Error Handling in PHP

php-training-in-gurgaon
Error handling is the process of catching errors from the program and then taking appropriate action. Before proceeding for error handling you should get to know how many types of errors occurred in PHP. Notices: These are non-critical errors that occurred while executing a script - for example, accessing a variable that has not yet been defined. By default, such errors are not displayed to the user at all - although, as you will see, you can change this default behavior. Warnings: These are more serious errors - for example, attempting to use a file (using include() method) which does not exist. By default, these errors are displayed to the user, but they do not result in script termination. Fatal Errors: These are critical errors - for example, creating an…
Read More

PHP – Strings Functions

php-training-in-gurgaon
String functions are the most important functions frequently used in PHP. String is the sequence of characters, like "Let’s learn String functions”. There is no installation required to use string function. Example <?php $name = "Hirdesh Bhardwaj"; print($name); ?> String Concatenation Operator To concatenate two string variables together, we use the dot (.) operator − <?php $txt1="Hello Readers"; $txt2="8756"; echo $txt1 . " " . $txt2; ?> Using the strlen() function The strlen() function is used to get the length of a string. <?php $txt=”Webs Jyoti”; echo strlen($txt); ?> This will produce the following result – 10 (including space) Using the strpos() function The strpos() function is used to search for a text or character within a string. If the value is found then this will return the position of…
Read More

Require () and Include () function in PHP

php-training-in-gurgaon
The Include() and require() statements are used to insert codes written in other files, in the flow of  execution. The main of using include and require functions to integrate one page code or content into another page. You can maintain usually some repeated functionality in the form of PHP file and finally you can call it wherever you want. See, the following example demonstrates how to integrate a menu content in other pages of PHP. There is a page in menu.php and it can be included in some other pages of the website. Menu.php <a href=”index.php”>Home</a> <a href=”services.php”>Services</a> <a href=”about.php”>About Us</a> <a href=”contact.php”>Contact Us</a> The following page index.php uses above menu.php content. See the below code how it follows <head> <title>My Web page</title> </head> <body> <?php include  “menu.php “; ?> </body> Difference between Include…
Read More

The While Loop

php-training-in-gurgaon
A While loop is used when we have to repeat a set of statements as long as the condition is false. It could be the best where number of repetition is not known earlier or in advance. It can be explain in plain English as "Keep doing something until a condition is true". Syntax: while (condition) { //  Set of statements goes here; } Example <?php $ct=5; while($ct<=50) { echo  $ct . "<br>"; $ct = $ct+5; } ?> Output: 5 10 15 20 25 30 35 40 45 50 The do…while loop example: <?php $i = 1; do { $i++; echo  $i . "<br>"; } while($i <= 3); ?>  Output: 2 3 4 Difference Between while and do…while Loop: With a while loop, the condition to be evaluated is tested…
Read More

The For Loop

php-training-in-gurgaon
PHP for loop can be used to traverse set of code for the specified number of times. For example if you want to repeat something ten or twenty times. It should be used if number of iteration is known otherwise I recommend you to use while loop. Syntax: for (Initialization; Condition; Progressive) { //set of statements to be executed; } Parameters: Initialization: Initialize the loop counter value Condition: Check for condition. If it evaluates to TRUE, the loop continues. If FALSE then the loop ends. Progressive: Increase / Decrease the loop counter value Example: for($var=1; $var<=20; $var=$var+1) { echo $var ." "; } Output: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 Example: to display 1st 20 natural…
Read More

Arrays in PHP

php-training-in-gurgaon
An array is a data structure that stores similar type of values in a common variable. Arrays are also called homogeneous data type. For example if you want to store 50 numbers then instead of defining variables it is easy to define an array with size of 50. In PHP, the array() function is used to create an array Arrays can store numbers, strings and any object but their index will be represented by numbers. By default array index starts from zero. $x=array("laxmi","hirdesh","rahim","ashu","amit"); // To count number of elements stored in array x echo count($x); // To populate value from any specific index or position //echo $x[1]; // output – Hirdesh // To print all elements in array x - using for-each loop echo " <br>Names are :"; foreach ($x…
Read More