0%
Loading ...

Parvesh Sandila

Parvesh Sandila is a passionate web and Mobile app developer from Jalandhar, Punjab, who has over six years of experience. Holding a Master's degree in Computer Applications (2017), he has also mentored over 100 students in coding. In 2019, Parvesh founded Owlbuddy.com, a platform that provides free, high-quality programming tutorials in languages like Java, Python, Kotlin, PHP, and Android. His mission is to make tech education accessible to all aspiring developers.​

Looping Statements in PHP

Looping statements help us to run a piece of code again and again. For example, you want to show 1 to 100 on your page. In normal cases, you have to write echo 100 times with the number to show 1 to 100 on the web page. But with the help of a loop, you can do this task very easily by writing an echo only once. There are three looping statements in PHP. for loop while loop do-while loop Now we will learn each looping statement in detail. For loop: – for loop is used to run a piece of code for a certain number of times. For loop take three expressions. In the first expression, we initialize a variable after that in the second expression we write and condition, and in the last expression we increment or decrement the variable. To understand it you can check the following syntax to define for loop in C. for (initializationStatement; testExpression; updateStatement) { // statements inside the body of for loop } Check this example. In this example, we will write 1 to 10 using for loop. Example Program: <?php for($i=1;$<=10;$i++){ echo “$i\n”; } ?> While loop: – If you want to run a piece of code again and again until a certain condition is true. You can use a while loop. while loop takes only a single expression which is a conditional expression. Check out the syntax to define a while loop in PHP. while(condition){ //body of the loop } Here is an example of a while loop. Example Program: – <?php $i=1; while(i<=10){ echo “$i\n”; $i++; } ?> Do while loop: – The do-while loop is the same as the while loop but there is a small difference. In case of the false condition in the first iteration of the while loop, the Body of the while loop would not run. But in the case of the do-while loop. It will run. because it checks the condition after running the body of the loop. Check out the syntax to define the do-while loop in PHP. do{ //body of the loop }while(condition) Example Program: – <?php $i=1; do{ echo “Hello”; }while(i!=1) ?>   Parvesh SandilaParvesh Sandila is a passionate web and Mobile app developer from Jalandhar, Punjab, who has over six years of experience. Holding a Master’s degree in Computer Applications (2017), he has also mentored over 100 students in coding. In 2019, Parvesh founded Owlbuddy.com, a platform that provides free, high-quality programming tutorials in languages like Java, Python, Kotlin, PHP, and Android. His mission is to make tech education accessible to all aspiring developers.​ new.owlbuddy.com

Looping Statements in PHP Read More »

Branching Statements in PHP

In this tutorial, we will learn Branching Statements in PHP. Branching statements allow us to control the flow of the program. For example, if you want to run a piece of code only if a certain condition would be true in this kind of situation branching statements can help you a lot. Here is a list of available branching statements in PHP. Available Branching Statements in PHP: – Now we will learn about all the branching statements in detail. If statement: – In case you want to run a piece of code only if a certain condition would be true. In this kind of situation, you can use the if statement. For example, you are creating a web page for student admission where a student can only apply for a course if he/she already has done bachelor’s degree. Please check out the following syntax to define the if statement in PHP. To understand the flow of the if statement. Please check out the following flow chart diagram of the if statement. Check the following example program to understand this if statement clearly. Example Program: – We can use various types operators to write the condition in branching statements in PHP such as conditional operators and logical operators. If else statement: – Now we know about the if statement. In the if statement we can run a piece of code only if the condition is true, It means we don’t have any control in case of a false condition. To solve this problem we have the if-else statement. The if-else statement allows us to write code for both conditions true and false. Please check out the following syntax to define the if-else statement in PHP. To understand the flow of the if-else statement. Please check out the following flow chart diagram. Example Program: – Else if statement: – We use the else-if statement in case we have multiple conditions and we want to run a particular piece of code for different conditions. Please check out the following syntax to define the else-if statement in PHP. To understand the flow of the else-if statement. Please check out the following flow chart diagram. To understand it, Please follows the given example program. Example Program: – Switch statement: – We use the switch statement in case we have multiple options. for example, you have various courses and you want to open a different page for each course. Please check out the following syntax to define the switch statement in PHP. To understand the flow of the switch statement. Please check out the following flow chart diagram. Check the following example to understand the switch statement more clearly. Example Program: – Wooo hooo! Now that you’re familiar with branching statements in PHP, go ahead and use them in your daily coding exercises. Practice makes perfect, so make the most of these concepts in your programming routines. Happy coding! Parvesh SandilaParvesh Sandila is a passionate web and Mobile app developer from Jalandhar, Punjab, who has over six years of experience. Holding a Master’s degree in Computer Applications (2017), he has also mentored over 100 students in coding. In 2019, Parvesh founded Owlbuddy.com, a platform that provides free, high-quality programming tutorials in languages like Java, Python, Kotlin, PHP, and Android. His mission is to make tech education accessible to all aspiring developers.​ new.owlbuddy.com

Branching Statements in PHP Read More »

Function in PHP

In very simple language a function is a block of code that can be used to perform a specific task. In addition, we can use a function multiple times without writing it again and again. For example, you want to perform some mathematical task in your code several times. It means you have to write code several times to perform that mathematical task. But with the help of the function, you can write your mathematical task code only once and you can use it any number of times. Advantage: – Before digging deep into this topic. Here is a list of a few advantages of using functions in PHP. Code Reusability: We can call a function any number of times after defining it once. Less Code: When we use functions in code. It reduces the length of the overall code(program). Easy to Understand: Because we separate different programming logics into different functions so it becomes so easy to understand and maintain the code. Defining a Function in PHP: – Let’s check how to make and call a function in PHP Program. To make a function just write the function name with () and then write the body of the function. <?php // Defining function function hello(){ echo “Hello World<br>”; } // Calling function hello(); hello(); ?> Output: – Hello World Hello World After following the above Program example you would have a clear idea of how we can define and call a simple function in PHP. But do you know that we can also pass values to a function to perform some task? When we create(define) a function that can receive values this kind of function is known as Parameterised Function. Function with Parameter: Sometimes we need data to process in function. We can send data to a function while calling that function. Check the example below to understand it. <?php $name=”Owlbuddy”; // Defining function function hello($n){ echo “Hello “.$n.”<br>”; } // Calling function hello($name); hello($name); ?> Output: Hello Owlbuddy Hello Owlbuddy   Parvesh SandilaParvesh Sandila is a passionate web and Mobile app developer from Jalandhar, Punjab, who has over six years of experience. Holding a Master’s degree in Computer Applications (2017), he has also mentored over 100 students in coding. In 2019, Parvesh founded Owlbuddy.com, a platform that provides free, high-quality programming tutorials in languages like Java, Python, Kotlin, PHP, and Android. His mission is to make tech education accessible to all aspiring developers.​ new.owlbuddy.com

Function in PHP Read More »

Arrays in PHP

In simple words, an Array is a variable that makes us able to store more than one same kind of value using a single variable name. For example, you want to save the name of a hundred students in variables. It means you have to make 100 variables. But it makes your code so complicated and It is also time-wasting. Instead of spending so much time on making variables, you can store all 100 names of students in a single variable using an array. Here we will learn the basics of array-like how to define an Array and how to Initialize an Array in PHP etc. In an Array, values store using a single variable name. But we use the index number to add or fetch the value from Array. For example, you want to store the name of a hundred students in the student Array. Then you have to add values like the name of the first student on the 0 indexes of the student array, and the name of the next student on the 1st index like this. Defining and Initializing an Array: Defining an Array in PHP is so simple. The simplest way to define an array using the array() function. Check the example below to understand it clearly. <?php // Defining and Initializing an Array $students = array(“Ali”, “Sameer”, “Mohan”); ?> Fetching Values from Array: Fetching values from the array is so easy there is a print_r() function. By using this function you can fetch values and structure of the array. <?php // Defining and Initializing an Array $students = array(“Ali”, “Sameer”, “Mohan”); // Display the students array print_r($students); ?> In case you want to fetch values from the array and see the detailed structure of the array. There is another function var_dump() you can use this. Check the program below to check var_dump(); <?php // Defining and Initializing an Array $students = array(“Ali”, “Sameer”, “Mohan”); // Display the students array var_dump($students); ?> Types of Array in PHP: There is a total of three types of arrays in PHP. We will try to understand each type of array using Examples. These three types are as follows Indexed array Associative array Multidimensional array Indexed array: Indexed Arrays are simple arrays in which we save values on the index using the array() function as we saw in our previous examples. <?php // Defining and Initializing an Array $students = array(“Ali”, “Sameer”, “Mohan”); $marks[0]=80; $marks[1]=90; $marks[3]=85; print_r($students); print_r($marks); ?> Associative array: In an associative array, we save values in the key-value form. For example “Ali”=>80, “Sameer”=>90, “Mohan”=>85. Check this program <?php // Defining and Initializing an Array $stumarks = array(“Ali”=>80, “Sameer”=>90, “Mohan”=>85); $marks[“Ali”]=80; $marks[“Sameer”]=90; $marks[“Mohan”]=85; print_r($stumarks); print_r($marks); ?> Multidimensional array: Multidimensional Arrays are also known as an array of arrays. Mean instead of storing values on the index of an Array we save an array on the indexes of an array. Check the following example. <?php $studentInfo = array( array( “name” =–> “ali”, “marks” => 80, ), array( “name” => “Sameer”, “marks” => 90, ), array( “name” => “Mohan”, “marks” => 85, ) ); print_r($studentInfo); ?>   Parvesh SandilaParvesh Sandila is a passionate web and Mobile app developer from Jalandhar, Punjab, who has over six years of experience. Holding a Master’s degree in Computer Applications (2017), he has also mentored over 100 students in coding. In 2019, Parvesh founded Owlbuddy.com, a platform that provides free, high-quality programming tutorials in languages like Java, Python, Kotlin, PHP, and Android. His mission is to make tech education accessible to all aspiring developers.​ new.owlbuddy.com

Arrays in PHP Read More »

Operators in PHP

Operators are special symbols that tell to PHP processor to do some special operations. For example, there is a + operator which tells PHP Processor to add two numbers (4+5). There are various operators available in PHP and they are divided into some categories. List of Categories: Arithmetic Operators Comparison Operators Assignment Operators Inc/Dec Operators Logical Operators String Operators Array Operators Now we will learn about each category in detail. We will learn which operators are in each category and how they work. Arithmetic Operators: – There is a total of five operators in this category. Arithmetic operators are used to perform some basic mathematical operations. Operators in this category are +,-, /, *, %. Checklist of Arithmetic Operators. Operator Name Description Example + Addition Add Two Number 10+5 – Subtraction Subtract the second number from the first number 10-5 * Multiplication Multiply Two Number 10*5 / Division Division of Two Number 10/5 % Modulus Return remainder after Division 10%5 Comparison Operators: – Comparisons operators are used to compare two numbers. For example to check which number is greater than the given numbers (10>5). The result of comparison operators comes in Boolean form mean 10>5 result of this would be true. The list of operators in this category is as follows. Operator Name Description Example == Equal Return true if the first value would equal to second. 10==10 === Identical Return true if both operands would be of the same data type. 10===10 != Not equal Return true if both values are not the same. 10!=5 !== Not identical Return true if both values would not be of the same type. 10!===5 < Less than Return true if the first value will be less than second 10<20 > Greater than Return true if the first value will greater than second 10>5 <= Less than or equal to Return true if the first value will be less than or equal to second 10<=5 >= Greater than or equal to Return true if the first value will be greater than or equal to second 10>=5 Assignment Operators: – The most common Assignment operator is =. Assignment operators are used to assign value to variables. There is a total of six assignment operators check this list. Operator Name Description Example = Assign assign value to variables $num=10 += Add and assign Assign a value to the variable after adding a value on the right-hand side in the previous value of the variable. num+=10 ($num = $num+10) -= Subtract and assign Assign a value to the variable after subtracting the value on the right-hand side from the previous value of the variable. $num-=10 ($num=$num-10) *= Multiply and assign Assign a value to the variable after multiplying the value on the right-hand side with the previous value of the variable. $num*=10 ($num=$num*10) /= Divide and assign quotient Assign a value to the variable after dividing the previous value of the variable with the value on the right hand. $num/=10 ($num=$num/10) %= Divide and assign modulus Assign the remainder to the variable after dividing the previous value of the variable with the value on the right hand $num%=10 ($num=$num%10) Inc/Dec Operators: – Increment and Decrements are unary operators means it only works with a single operand. These operators are used to increase or decrease the value of a variable by one. Both Inc and Dec come in two types pre-increment and post-increment. Operator Name Description Example ++ Increment Increment the value of $a by one, then return $a Return $a, then increment the value of $a by one ++$a $a++ — Decrement   Decrement the value of $a by one, then return $a Return $a, then Decrement the value of $a by one –$a $a– Logical Operators: – Logical Operators are used to check logical relations between operands. These operators are used to perform bit-level operations. Operator Name Description Example and And Return TRUE if both $op1 and $op2 are true $op1 and $op2 Or Or Return TRUE if either $op1 or $op2 is true $op1 or $op2 xor Xor Return TRUE if either $op1 or $op2 is true but not both $op1 xor $op2 ! Not Return TRUE if $op1 is not true ! $op1 && And Return TRUE if either $op1 and $op2 are true $op1 && $op2 || Or Return TRUE if either $op1 or $op2 is true $op1 || $op2 String Operators: – String operators are used to perform some special operations with Strings. Operator Name Description Example . Concatenation Concatenate $str1 with $str2 $str1 . $str2 .= Concatenation and Assignment First will concatenate $str1 with $str2, then assign the final concatenated string to $str1, $str1 .= $str2 Array Operators: – Array operators are used to perform special operations with Arrays. Operator Name Description Example + Union Union of $num1 and $num2 $num1 + $num2 == Equality Return TRUE if $num1 and $num2 have same key/value pair $num1 == $num2 != Inequality Return TRUE if $num1 is not equal to $num2 $num1 != $num2 === Identity Return TRUE if $num1 and $num2 have the same key/value pair of the same type in the same order $num1 === $num2 !== Non-Identity Return TRUE if $num1 is not identical to $num2 $num1 !== $num2 <> Inequality Return TRUE if $num1 is not equal to $num2 $a <> $b Parvesh SandilaParvesh Sandila is a passionate web and Mobile app developer from Jalandhar, Punjab, who has over six years of experience. Holding a Master’s degree in Computer Applications (2017), he has also mentored over 100 students in coding. In 2019, Parvesh founded Owlbuddy.com, a platform that provides free, high-quality programming tutorials in languages like Java, Python, Kotlin, PHP, and Android. His mission is to make tech education accessible to all aspiring developers.​ new.owlbuddy.com

Operators in PHP Read More »

Strings in PHP

The string is commonly described as a collection of characters. Mean a string can be a collection of numbers, alphabets, or special symbols for example “Hello World”. In PHP you can define a string in the program in two ways by using single quotes(‘ ‘) or by using double(” “) quotes. Here we learn about strings, basic functions in strings, escape-sequence, and the difference between single and double-quote strings. Difference between Single and Double Quote Strings: – We can write strings in PHP in both single and double quotes. But there is a certain difference between both. If you write a string in single quotes it will take string literally. Suppose you have a variable $num=10; and if you write something like this ‘Value of num=$num’. In this case, it will show the same. But if you will write this in double quotes the variable name will be changed with its value. To understand it more clearly follow the given example. <?php $num =10; echo ‘value of num = $num’; echo “value of num = $num”; ?> Escape-Sequence in strings: – These are some special escape sequences in PHP that we can use with strings. These escape sequences get replaced with special values. Check these escape sequences. \n is replaced with the newline character. \\ is replaced with a single backslash. (\) \r is replaced with the carriage-return character. \t is replaced with the tab. \” is replaced with a single double-quote (“). \$ is replaced with the dollar sign itself ($). Basic string Functions: – Here we will check some of the basic functions with would so helpful to you while working with strings. Here is like of some basic string functions in PHP. strlen(): function to check the total number of characters in a string. str_replace(): function to replace part or parts of a string with another string. str_word_count(): function to check the total number of words in a string. strrev(): function to reverse a string in PHP. Parvesh SandilaParvesh Sandila is a passionate web and Mobile app developer from Jalandhar, Punjab, who has over six years of experience. Holding a Master’s degree in Computer Applications (2017), he has also mentored over 100 students in coding. In 2019, Parvesh founded Owlbuddy.com, a platform that provides free, high-quality programming tutorials in languages like Java, Python, Kotlin, PHP, and Android. His mission is to make tech education accessible to all aspiring developers.​ new.owlbuddy.com

Strings in PHP Read More »

Data Types in PHP

PHP supports a total of eight data types available in PHP that are integer, float, string, boolean, array, object, resource, and NULL. These data types are used to define what kind of data a variable can store. Now we will check out every data type in detail with the help of examples. Integer: – In an integer data type variable, we can store integers mean decimal numbers, octal numbers, and hexadecimal numbers. These numbers may be signed or unsigned depending on requirements means as 10 or +10. <?php $num1 = 123; // integer number echo $num1; echo “<br–>”; $num2 = -123; // signed integer echo $num2; echo “<br>”; $num3 = 0x1A; // hexadecimal number echo $num3; echo “<br>”; $num4 = 0123; // octal number echo $num4; ?> Float: – Using this data type we can store decimal values like 2.5 or 3.2555 etc. <?php $num = 1.234; echo $num; echo “<br>”; ?> String: – In strings data type we can store a sequence of characters, special symbols, or numbers. To store any value in string type value must be enclosed in single or double quotes like ‘Owlbuddy’ or “Owlbuddy”. <?php $str1 = ‘Owlbuddy’; echo $str1; echo “<br>”; $str2 = “Owlbuddy”; echo $str2; echo “<br>”; ?> Boolean: – Boolean can hold only two values which are true or false. You can not store any other value in the boolean type. Boolean is so helpful while working with conditional statements. <?php $flag = true; echo $flag; ?> Array: – The array can be used to store the collection of similar kinds of data in a single variable. Suppose you want to store the age of 10 students you can easily do this using Array. <?php $colors = array(“Red”, “Green”, “Blue”); echo $color[0]; ?> Object: – The object allows us to store different kinds of data at once for example you created an object called Chair. The object Chair can be used to store data about a chair such as chair_height, chair_Price, and chair_color. Apart from storing data in an object you also mention relation functions in an object. <?php // Class definition class car{ // properties public $name = “BMW”; // methods function show_name(){ return $this—>$name; } } // Create object from class $car1 = new car; ?> Resource: – This type of variable is used to hold a reference to an external resource. <?php // Open a file for reading $path = fopen(“file.txt”, “r”); echo “<br>”; ?> Null: – This data type is used to represent any empty variable. <?php $var = NULL; echo $var; ?>   Parvesh SandilaParvesh Sandila is a passionate web and Mobile app developer from Jalandhar, Punjab, who has over six years of experience. Holding a Master’s degree in Computer Applications (2017), he has also mentored over 100 students in coding. In 2019, Parvesh founded Owlbuddy.com, a platform that provides free, high-quality programming tutorials in languages like Java, Python, Kotlin, PHP, and Android. His mission is to make tech education accessible to all aspiring developers.​ new.owlbuddy.com

Data Types in PHP Read More »

Constants in PHP

We already learned about variables. I assume you would have a clear idea about variables. As we know the value of a variable can be changed numerous times throughout the program. but on the other hand value of constants can not change. Constants are also used to store data like variables but once constants get initialized values can not be changed. With the help of constants, we have stored data that would not change in the whole program for example store data like DB_username, DB_password, or BASE_URL in constants. Constants help us to make sure that our data would not change throughout the whole program even if not by mistake by the programmer. If you define a constant in a program the only way to change the value is to change the value where you define the constant for the very first time in the program. In PHP we can define constants using the define() function. This function accepts two parameters first one is the name of the constant and the second is the value of the constant. After defining the constant you can access it anywhere in the program by using its name. Please check the following example program to understand constants more clearly. <?php //defining constant Here define(“language”, “PHP”); //accessing constant with name echo ‘I Love ‘ . language; ?>   Parvesh SandilaParvesh Sandila is a passionate web and Mobile app developer from Jalandhar, Punjab, who has over six years of experience. Holding a Master’s degree in Computer Applications (2017), he has also mentored over 100 students in coding. In 2019, Parvesh founded Owlbuddy.com, a platform that provides free, high-quality programming tutorials in languages like Java, Python, Kotlin, PHP, and Android. His mission is to make tech education accessible to all aspiring developers.​ new.owlbuddy.com

Constants in PHP Read More »

Variables in PHP

Variables are used to store data like strings or numbers for example min_age=18. The value of the variable can be changed numerous times throughout the code. It is so easy to define variables in PHP just write $sign and then a variable name like this $min_age=18. You do not even need to mention the data type of variable. Because PHP will automatically choose the correct data type of variable according to the value stored in a variable. PHP is a Loosely Typed language: – PHP is a programming language known for its loose typing. This means that in PHP, variables can easily switch between different data types without needing explicit type declarations. While this flexibility can lead to some unexpected issues, it also allows developers to work quickly and creatively, making PHP a popular choice for web development, whether you’re building an e-commerce website or a content management system. Declaring a Variable: – Declaring a variable means announcing its existence and specifying its data type. When you declare a variable, you are telling the computer that you intend to use a specific name for a storage location in memory. Initializing a Variable: – Initializing a variable means giving it an initial value at the time of declaration or later in your code. It’s the act of assigning the first value to a declared variable. If you declare a variable but do not initialize it, its value will typically be undefined or garbage (contains whatever was in that memory location previously). Basic Things to keep in mind while creating Variables in PHP: – To initialize a variable you just need the assignment operator (=) then write the value of the variable for example $min_age=18 or $name= ”Mohit”. Now we will check this basic example to understand Variables in PHP. The output of the above-written code will be this: “Hello Mohit Your age is 22. Your height is 5.9 and You are from Delhi“. I hope now you would have a clear idea about how to declare and initialize variables in PHP. Please continue with the next tutorials of this series. Parvesh SandilaParvesh Sandila is a passionate web and Mobile app developer from Jalandhar, Punjab, who has over six years of experience. Holding a Master’s degree in Computer Applications (2017), he has also mentored over 100 students in coding. In 2019, Parvesh founded Owlbuddy.com, a platform that provides free, high-quality programming tutorials in languages like Java, Python, Kotlin, PHP, and Android. His mission is to make tech education accessible to all aspiring developers.​ new.owlbuddy.com

Variables in PHP Read More »

Hello World program in PHP

We already learned how to install and start the virtual server on a PC. Here we will check out how to write a simple Hello World program in PHP to display Hello World on the screen. First of all, we will create a folder in the htdocs folder to save our PHP files. I am creating a folder named PHPTutorials. You can see it in the image given below. In this PHPTutorials folder, we will create a file “HelloWorld.php”. It’s important to know that PHP files are saved using the .php extension. Note! You can use any text editor to write PHP code like Notepad, Notepad++, Sublime Text. We will use here Sublime Text. Basic PHP code Syntax: To keep PHP code separate from HTML and CSS we have to write PHP code in Canonical PHP tags, which means we will write the whole PHP code inside these tags. Now we will see an example of the Hello World program. As you can see we have written our PHP code inside Canonical PHP tags which keep it separate from the rest of the code. we have used echo to show output on the screen which is Hello World. Now please save this file as HelloWorld.php in the PHPTutorials folder. After saving it we will run this code in the browser. Note! Please make sure the Apache server is in start mode in your xampp software. To run the code make sure your XAMPP server is on then type this localhost/PHPTutorials/HelloWorld.php chrome address URL bar and hit enter. You will see output like this. Parvesh SandilaParvesh Sandila is a passionate web and Mobile app developer from Jalandhar, Punjab, who has over six years of experience. Holding a Master’s degree in Computer Applications (2017), he has also mentored over 100 students in coding. In 2019, Parvesh founded Owlbuddy.com, a platform that provides free, high-quality programming tutorials in languages like Java, Python, Kotlin, PHP, and Android. His mission is to make tech education accessible to all aspiring developers.​ new.owlbuddy.com

Hello World program in PHP Read More »

Scroll to Top
×