Crash Course in PHP | PHP tutorial for Beginners in 2021 | Great Learning

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
php is a popular general purpose scripting language that is especially suited to web development fast flexible and pragmatic php powers everything from your blog to the most popular websites in the world you can add delete modify elements within your database through php using php you can restrict users to access some pages of your website it can also encrypt data php performs system functions that is from files on a system it can create open read write and close them along with that it can handle forms that is gathering data from files save data to a file or through email you can send data return data to the user hello learners in this tutorial we will be learning about the php [Music] if you haven't subscribed to our channel yet i want to request you to hit the subscribe button and turn on the notification bell so that you don't miss out any new updates or video releases from great learning if you enjoyed this video show us some love and like this video knowledge increases by sharing so make sure you share this video with your friends and colleagues make sure to comment on the video any queries or suggestions and i will also respond to your comments hello learners let's get started with the course of php my name is gaurav and welcome to great learning moving to the agenda first we will be discussing about what is php is application is syntax then we will see the installation of php moving further we will be knowing about comments in php along with variables and then we will see variable scope that is global variable static variable and local variable following that we will be also knowing that different data types in php along with control statements such as if else if else and then we will see loops such as while and for then moving ahead we will be discussing about different types of operators arithmetic relational logical bitwise then moving next we will be discussing about what is string and different functions that are involved in string and also we will be knowing about functions and whatever the different arguments that can be passed inside a function then we will be knowing about call by value as well as call by reference and at last we will be discussing about arrays so in arrays we are having three different types of arrays in php indexed array associative arrays and multi-dimensional array so we will discuss each topic in detail now let's see what is php so php is an open source scripting language that is used to provide secure web fronts in simple words we can say that it provides people to make web pages right also it is used to execute it on the server as a backend language yeah so php is used as a backend language so let's take an example of google chrome we never know the logic of google chrome of the back end how how is it working right because if somebody knows the logic of google chrome then then other company will copy the logic and then they will create their own search engine right so that's what so php will be executed but nobody knows right which language you are using at backend so php is the language that is used for the backend now next point it is free to download to use so it's a open source language you can download it from internet and also php can be applied in html syntax right so if you want to make a website you can use php in a backend so this is a basic idea about php now moving next let's see the syntax of php so the syntax of php is here is a less than symbol and then you will add question mark and then you will write php and inside that you write the statements whatever you want to write and then we'll write once again question mark and then we'll write here greater symbol so this is the basic syntax of php now let's see some applications of php as i told you that php is used to develop web pages right along with that php is also used to create gui applications php is also used in graphic design as well as image processing next it is also used in graphical representation such as it is used in charts it is used in graphs as well as for scattering dot plots also you can use php now we will be seeing the installation of php so for php installation i will be installing xampp as well as visual studio right i will going on my google chrome and here i will click on xampp just type their xampp and here you will see the first link xampp installer and download for apache friends i will click on this and here you can see that i am having sam for windows right so i will click on this so what is zamvio so you can see that xampp is the most popular php development environment right now as i told you that i have to install visual studio also so i will click on visual studio code and here you can see that this is the first link of visual studio code let it open it and now if i scroll down then i can see that i am having visual studio call for windows and then mac and then linux also so i will be installing for windows so i am clicking on this and here you can see that it's installing for me right so yeah let it stall now here you can see that my xampp as well as my visual studio code has been installed now i will go on the folder downloads so i will go on the downloads option so here you can see that in downloads i'm having xampp and visual studio right so i will click on xampp and it's asking me the permission i will give yes and then you can see that here is asking continue with installation i will say yes and then i will click on ok i will click on next then just go on next so yeah now it's asking me select a folder so you can see that it's in my c drive so i will just copy this and then i will click on next language will be english so now you can see that it's telling setup is ready to begin install xampp on your computer i will click on next and then it's taking time to install let's wait to install this jam so you can see that now is asking for the finish so i will click on finish then you can see that here i am getting apache and mysql so just click on here start and just click on my sql start now your this apache and my sql is running now what i will do i will go on google chrome and here if i'm typing localhost so on localhost you can see that i'm getting this page right so i'll just click on phpmyadmin and you can see that we are at php myadmin now what i will do here i will install visual studio so once again i will go on downloads and then here i will install visual studio so just click on i accept the agreement and then click on next install so it will install here and just click on finish to complete the visual studio code setup i am already having visual studio so i will just skip this and now after this what i will do just go on this pc and where was your folder your folder was a local disk c xampp right and after going into this folder just see where is htdocs right so just see htdocs folder so htdocs folder you will see all these files now create here one folder i'll create a new folder here great learning and inside this i will click on the right button of my mouse and here you can see the option open with code this is visual studio code so i will click this and you can see that i am getting great learning here right so now what i will do i will just close this and i will click on this button so it's asking me to create a new file i will click on it and then i will write here one dot and since i will be working in php so i'll write here php so this is my php file right now what i will do so now let's write the basic syntax of php so so before writing the basic syntax of php let's see that if it's opening or not so i will just go on google chrome and here i will write localhost and here you can see that it's doing great learning so if i'm executing it it's doing one dot php right so in one dot php if i'm opening so here you can see that i'm not seeing anything in the reason is because i didn't started coding yet so now what i will do i will write a basic code in php so let me write the syntax of php and inside this i will write simple echo so we will study about echo later but as of now you just know that echo is used to display the output on the screen right so inside this echo i will write welcome to great learning and i will put semicolon and then i will save it with ctrl s and if i am going to my website and if i am here refreshing it you can see that i am getting welcome to create learning so this is my website and here you can see that i am using php in back-end so this is the basic idea about the php installation so now let's see what is comments in php so here comments are the description of information or details of source code in a program right and also it is ignored by compiler and will not execute now you might have a question when we can use comments so let's take an example of any code let's suppose that if we are writing a code in php and inside that we are using some functions or method and if we want to give the brief description about that function or method then we can write it into the comment right so suppose that if you are writing any program and after two to three years you if you want to recall that program so comment will be helpful at that time right because you will give the information about that code so as we know the syntax of php is less than then question mark then we'll write php and if we want to close then i will write here question mark and then it will be a greater than symbol right and inside that i will write some functions right so inside that let's suppose that if i'm writing echo function so as of now you just understand that echo function is used to display the output on that screen right so inside this eco function i will write hello world okay and then what i will do i will use comment so i will write echo function is used to print or you can say that equal function is used to display the output on screen so what will happen here when i will execute this program then this comment will not be executed so that's why i have written here it is ignored by the compiler and will not execute right now let's move to multi-line commands so in multi-line commands i can write here slash and then s trick and if i want to close then i can add s trig and then slash and inside that i can write a piece of information in multiple lines right now let's see the coding example of this comment so first i will write the syntax of php so i'll write less than and then question mark and then i will write php and inside this let me close so i'll close this and inside this php i will write echo and i will write here welcome to create learning and after that what i will do i will use comments i will write here comments so for comment symbol will be double slash this is a single line comment so i'll write here echo function is used to display the output on screen right now let me execute this so i will press ctrl s and now here if i am refreshing it you can see that i am getting welcome to great learning right so this was all about single line comment right let me write here c right echo so now moving to multi-line comments as i told you that i can write a piece of information in multiple lines right so let me write it so what's the syntax of multi-line comments i will write here slash and then i will write here s trick and then after that i will close this with right so here you can see that this is the syntax for multi-line commands now as i told you that whatever is written inside a comment it will be ignored by the compiler so let me execute this but before that let me write some more points so i will write here let's suppose i'm writing here gaurav and then i'm writing great learning so you can see that i'm writing a piece of information in different lines right and let's suppose let's take any random thing i will write cgd anything and i will press ctrl s to save it and now if i'm going and if i'm executing here you can see that i am again getting the welcome to great learning right so this was all about single line and multi-line comments so moving next we are having variables so what are variables so variables are used to store values right and if you want to declare a variable in php then you have to use the dollar symbol right so let's suppose if i want to create a variable so i'll write first dollar and then i will write var variable and i can assign the value as 1 and even you can assign any value right next we are having variable name is case sensitive in php so what do you mean by case sensitive that means uppercase letters and lowercase letters are treated to be different let's take an example suppose this is a variable so i'm writing here dollar var and this is a variable dollar v a r so here you can see this is uppercase letter v this is a lower case letter v so here you can see that this is a capital letter of v this is a small case letter right so it will be treated as different right it can't be same so this is the meaning of case sensitive next we can see that php automatically connects with a data type to a variable while giving the value the best thing about that php is that if you are declaring any variable let's suppose that i am writing dollar and i am writing here var then you don't have to define its data type if you are writing here one then php will automatically associate with the data type it will get to know that its integer data type similarly if you're writing 1.1 and you're writing here you are creating variable then it will get to know it's a float data type and if you're writing let's suppose you see then it will get to know it's a character data type so this is the best thing about php you don't have to declare its data type it will automatically get to know now moving next let's see some example of php right so as i told you that eco function is used to displace the output on the screen right now let's see the coding example of it so for creating a variable let me first write the syntax of php so i've written the syntax of php and then after that what i will do i'll create a variable so for creating a variable i will write dollar and redmi night variable and inside this i will give let's say the value 1 and if i want to print out this variable let me write here semicolon and for painting i will use eco and then i will write here variable name that is dollar var right and let me close so so now you can see this is my variable and if i want to print out this variable so let me go on to the website and on execution you can see that i am getting the variable value as 1 right you can also use here as i told you that in php you don't have to declare a data type so i can use a string variable also so i can write here dollar variable and here let me give the variable name as variable 1 i will give here as a variable 2 and here i will write a string value let's suppose gaurav i will write here and then after that i will write dollar va variable 3 and here i can assign 1.1 this is a float vario now if i want to print out so let me copy this statement and here i will give variable 1 variable 2 and then variable 3 and now if i am executing it ctrl s i will write and you can see if i'm getting then you can see that i'm getting one goal of 1.1 but i'm getting all this in the same line right but i want these values to be printed or to be displayed on the different line so for that for that i will be using a br tag that is an html tag right so what i will do here i will write here dot and then i will write here br and i will put insider inverted comma right so this is the beer tag that is the html that i will use so that okay so this is the br tag that i will be using so that i can get the values in different lines so on if i'm going to this and then if i'm executing you can see that i'm getting the values in different line so this is the basic idea about variables now after knowing what variable is we are having variable scope that is primary of three types the first one is local variable global variable and static variable so now let's understand what is local variable right so local variable is a variable that is declared inside the function or you can say in the method and it can't be accessed outside the function right now let's see an example so this is a simple syntax of php right so if you want to create a function in php then you can create by writing function and then function name right so here i am creating my function so i have written function and here i have given the function name marks so inside this function i have created my local variable and i have assigned the integer data type value to it right 96. now here what's the point as i was telling you about the local variable so the point is here i have created the function and inside this i've created my local variable right so i can't access it from the outside the function right so if i'm writing outside the function this function is closed here right and if i'm writing outside the function echo and then if i'm writing echo and then i writing dollar marks then you will get an error it will not print right so if you want to call a function then how can you call a function because we know that we can't directly print function right a function has to be revoked or it has to be called right i will discuss more about the function later on but as of now you just know that if you want to print function then you have to call it right so i'm calling the function marks right with the function name so this is the name of the function if i'm calling it it will check oh my marks value is 96 and inside this function inside this function i am having the echo method or echo function and it will print local variable inside the function is 96 right but i can't directly write outside the function echo and then i can write the marks it will not print let me give you idea by showing you the practical example so now let's see the example first i will create the syntax of php and then after that i will create a function so for creating a function i will write function this is the syntax and the function name so let's suppose your function name is you can see that student i will take you and inside this student function i will create a variable that is local variable because local variable is created inside a function or method you can say so i will write here dollar marks and i will assign the value so i am taking here integer value so i will write here let's suppose 87 and then after that i will write here echo echo and then i will write inside this echo the marks of a student of a student is and then i will write here dot so dot is used for concatenation right so here i will write dollar marks right now you might have a question that if you want to print this function right then how you can print this function you can't directly print this function you have to call it the function right so this is my function right now as i told you that function can't be directly printed you have to call it function let me show you so this is the function that i have created right now as i told you that if you want the statement inside a function to be printed out you have to call the function right see let me check it right now i'm not calling this function right and if i'm pressing ctrl s and if i'm going and then seeing you can see that nothing has been printed right so to print this out inside the function i have to call this function so i will write here student and now so if you want to call a function then just write a function name right so now i will call this function and you can see that i am getting the marks of a student is 87 right but i was telling about the local variable right i was telling that local variable can't be accessed outside the function right so my function has been closed here right now if i'm writing here eco and then i'm writing here dollar and then marks so can i access my local variable let me check and if you can see that i am getting an error right because as i told you that local variable can't be access outside the function so this was the concept about local variable so the next variable we are having is global variable so what is global variable global variable is generally declared outside the function and it can be accessed throughout the program right now global variable can be accessed inside the function using global keyword as i told you that global variable can be accessed throughout the program but if you want to access inside the function then you have to use the global keyword let's see so this is my syntax of php and inside this you can see that global variable is declared outside the function and i've given the name as adt at tech and here i have written a string value welcome to great learning then i have created my function and inside this function you can see that i've written my global variable with a global keyword so here i've written global and then i've written the name of my global variable that is edt and do not forget to write dollar before that and then i'm writing here echo and then i'm writing variable which is inside the function and then i'm writing here dot to concatenate and then after that i'm calling this function right now as i told you that this is a global variable that means it can be accessed throughout the program right so i can write outside the function also echo and i can write variable which is outside the function and once again i am doing the concatenation now let's see the example in practical coding of global variable so now okay so let me write my global variable so i will write here dollar and then i will write let's say attack i will write as a variable name and i will write here great learning so this is my global variable because i have declared outside the function and this is my function so inside this function if i want to declare global variable then i have to write global and then i will write here at tech now what i will do here let me remove this i'll write that tech company name is that tech company name is and then i will write here now i will write dollar adt so this is my function right if i want to call this function then i have to write the function name so i have written here student right as i told you that this is a global variable that means it can be accessed throughout the program so what i will do here i will write echo and i will write here the edtech company name outside the function and then once again i will write dot for concatenation and then i will write here dollar and the name of the company at tech right and the name is edtech right so we have to write here edtech now if i'm executing it on execution you can see that the company name is great learning that company name outside the function is great learning but you can see that i am getting the output in the same line so for getting the value in different line we can use the html br tag so now what i will do i will use br text so let me write here br tag so if now i'm executing then you can see that i am getting that company name is great learning the tech company name outside the function great learning so this was the idea about global variable so the last variable that we are having is static variable so what is static variable so if i'm writing here let's say variable name so if i want to declare a variable in php i will write first dollar and then i will write variable so to declare a static variable i will write here static so this is my static variable okay so a static keyboard is used before the variable to declare a static variable right now next is it is declared in a local function right so it will be declared inside a local function so here you can see that this is my php syntax inside this i have created my function and inside this function i have created a static variable so a static variable is declared inside a local function now here you can see that inside this function i am doing the increment right and after that i am writing echo and inside echo i'm writing static variable marks is and then i'm concatenating it right and after that i'm using br html tag and i'm closing this function now you can see that if you want to call any function then you have to write the function name for calling it so here if you're calling this function you can see that static value was 87 right now there will be increment then i will be getting 88 right so as we know that echo is used to display the output on screen so i will getting the static variable marks is 88 right now this function will end always remember static variable will not lose its value when the function is ended so here you can see that first time i am calling i am getting 88 now once again i am recalling this function so now my static variable is 88 right now if i am calling it then there will be increment and my new value will be 89 and there will be a print of 89 value again once again i am calling through my function name again there will be increment here and my new value will be 90. so this is the concept of static variable now let's see in the practical example now let's execute then the concept of static variable so this is a function student and inside this let me write here i will declare here static variables i will write here static and then i will write here marks and let me assign as 87 and after that what i will do i will do the increment right and then i were writing the marks of the student right here the marks of the student of the student is and then i will write here marks so this is my function right now if i want to call this function what i will do here i will write here the function name itself so let me write ecobia inside this function because i will call this function several times so i want all the values to be printed on the next line right now let me execute this so here on executing you can see that the marks of the student is 88 right because there has been an increment so this is the first time i'm calling this function now if i'm calling again once again then you can see that i am getting the marks of the student is 89 why i am getting this because the static variable will not lose its value when the function exits right once again if i am calling it student and then you can see that so the the new marks value will be 90 right the marks of the string is 90. so this was my static variable so this was the concept of static variable whereas if we have taken the local variable and if we are calling the local variable so the value will not be incremented again and again the my value will be 88 even though if i call it's the several times then also my value will be 88 but in case of static variable there will be the increment 88 89 and 90. so next we are having echo and print function so what is eco function so as i told you the formal definition of echo it is used to display the output on screen right but remember echo doesn't have any return value right so if you want to write an echo function then you can write echo and then you can write echo so you can write this echo with parenthesis and you can also write echo without parenthesis right so it can be used with or without parentheses now moving ahead let's see the example where we have already seen the example of echo right so here you can see this is the syntax of php inside that i have created a variable information and this is a string variable welcome to great learning i've written here and then i'm writing echo function and inside that i am reading information is welcome to great learning right this dollar information this is my variable so it will print welcome to great learning so this is the basic idea about echo now coming to the preen function so just like eco it is also used to display the output on the screen but in print it returns the value as 1 that is integer value right and it can be also used with or without parenthesis so you can write print function like this also and you can also write print function in this way too right always remember that in print multiple arguments cannot be passed whereas in eco you can pass multiple arguments so now this is example of print function you can write the basic syntax of php and inside that you can write green great learning so let me show you the example first i will write print statements so i will write here the basic syntax of php and then after that i will write here print and then i will write welcome to great learning and then i will close this and now if i am executing it now it's doing welcome to great learning so you can see that print function is also used to display the output on the screen right and echo i have already showed you but once again i will show you echo if i'm writing and then executing then you can see that i will be getting the same output welcome to great learning so this was the basic idea about echo and print next we are having data types so let's see what are different data types present in php so in php we are basically three types of data types scalar data types special types of data types are there and then compound data types so in scalar data types we are having predefined data types which we have already seen earlier so in this we are having integer float string and boolean as we know that integer consists of integer value that is 1 2 and so on right now coming to the float it contains decimal value that means 1.235 for example now coming to the string string is a sequence of characters right so i can write gaurav and you have to put the string into double quotes now next we are having boolean so boolean will give us true or false right so now as i told you that in php you don't have to declare data type rights so if you are creating any variables i will write dollar and then i will write variable and if i am giving here one then it will automatically associate yeah that this is an integer data type if i am writing here one point five three two then it will get to know yeah this is a float data type similarly for a string if i'm writing dollar variable is equal to gaurav then it will get to know there's a string data type right so the next data type we are having compound data type right so this is a user defined data type as you will see about the array so what do you mean by array so array store multiple values in a single variable right now object we will see in ops concept right object oriented programming and then we are having the special types also that is resource and null right now coming to the null it is a special data type that means there is no value assigned right and then we are having also a resource in special types so these are the basic idea about different data types present in php now let's see the practical example so now let's see the implementation of different data types so i will write here dollar let's say i will write here integer and inside this i can give one two three now after that i will create a string variable and inside this i will keep quaraf now after that i will create a float variable so i'll write float and then i will give the value 9.0789 and now let me execute this so if i want to execute then i can have two method the first one is eco and another one is print both function will display the output on the screen so i am using here eco and then i'll write here echo dollar in the name of the integer variable and then i'll write echo br and let me copy and paste this and here i will change the variable name as a string and here i will change with float and now i will execute this so let me execute before executing i will put one more question now go and then br right so now if i am executing this so on execution you can see that i am getting the value of 123 gaurav and this float value now there is one more function that i will be using is variable term so variable dom will give me the data type with its value now let me execute with the variable term so what i will do here i will write here echo and then i will write variable dump and inside this i will write the variable of integer let's suppose right and if i'm executing it then you can see that i'm getting the data type that is int and then i'm getting the value 123 right similarly i can do it for string also right so what i will do here let me copy this so that i can get the string value on next line and again i will copy this and paste this and inside that i will write my string variable so i'll write here string and now if i'm executing it you can see am getting string six and then gaurav right so this is giving me data type that is string data type and gaurav along with the length if you count the length of the string i am having one two three four five six right let's suppose that if i'm writing here of sing and if i'm executing then you can see that i'm getting the length as 11 right so this was the basic idea about different types of data types moving next let's see what is control statements so in control statements first we are having if statement right so if statement will execute whenever the condition is true right and what happens if the condition is false so if the condition is false statement will be skipped right so let's see in syntax an example so if i'm creating here let's say variable dollar h and i am giving the age as 25 right so here in if condition if i am giving dollar h is greater than 18 and then inside this i am writing echo and then i'm writing person is eligible for vaccination right so if i'm writing this so you will see that this statement will execute right because the age is 25 right and 25 is greater than 18. what happens instead of 25 if i am writing here is let's say 17 so now if if we see this statement 17 is greater than 18 no so this statement will not execute and it will escape it so this is about if statement so the next statement we are having if and else so if the condition is true then the part will be executed if the condition is false else will be executed right let's take the same example if i'm writing here dollar h this is my variable and if i am writing here 25 and in the first condition inside this if i am writing dollar h is let's suppose that is greater than 27 right so here if i am giving this dollar h is greater than 27 so my age is 25 so is 25 greater than 27 no so if statement will be skipped and now it will zoom to the else statement so whatever the inside this else statement is there it will be executed so you can see that condition is true if part will be executed if condition is false else will be executed so this is about if and else statements now moving next we are having if else if statement right so now when we will use if else if or else so let's see the condition so as you can see that it is used to set out a new condition when first condition is false suppose if i am writing here if so as we know that the if statement will execute when the statement is true right now coming to the else if so else if statement will execute if this condition is false and this condition 2 is true then it will execute right and if both conditions are false then it will jump to the else statement and it will execute right so here it is written and execute if both our condition are false right so we got a little bit idea about conditional statement let's see in the practical example to get more clarity over this so now let's start with the fn else statement so i will create a variable dollar h and inside this i will give the value as let's suppose 27 and after this i will write here if age is greater than 18 and then inside this i will write echo let's say person is eligible for vaccination right and i will give another condition let's say else in other cases will give ego not eligible now let me save it and now if i'm executing you can see that age is 27 right so it will see 27 is greater than 18 so inside this if statement it will print person is eligible for vaccination so so on executing you can see that we are getting person is eligible for vaccination right now what i will do here instead of 27 if i am writing here 15 then you will see now this if condition is not satisfying because 15 is not greater than 18 so it will jump into the else statement and it will print not eligible so let me save this and if i am refreshing it you can see that not eligible right so this was the idea about if and else now i was talking about else if statement also right so let me give one more condition so if i'm giving condition here else if and inside that if i am giving suppose h is greater than 45 and then i am writing echo and then i will write person will get the vaccination on priority so let me save this and here you can see the age is 15 right i will change age here let's suppose 46 and now after saving if i'm executing it you can see that i will get my output person is eligible for vaccination right now here you can see that my age is 46 right and here i have used the elsif condition then also the statement inside the if condition is executed right you can see here person is eligible for vaccination the reason is so here you can see that inside if i'm writing if 46 is greater than 18 then it will print whatever is inside this if condition right and once it is printed it will skip all the conditions below it now if i want to print it here what i will do if i am writing here suppose if age is less than 18 person is not eligible for vaccination and here i will give age is greater than or equal to 18 then i will give person will get the vaccination on priority okay now this is my condition now if you see or else in other cases it will give not eligible now let me save this and if now i'm executing you can see that person will get the vaccination on priority right so this was my condition so this was all about f elseif and an else statement moving next we are having switch case statements so switch case statements are multi branch statements now let's understand how does the switch case works so here i will write switch and inside this switch i will pass a parameter let's say the parameter name is dollar x now inside this switch i will take the case so here i am writing case 1 right so if dollar x value is equal to 1 so whatever the statements are inside this case 1 it will be executed right and suppose if dollar x value is here 2 then it will not be execute it will execute right x equal to 2 and once the execution has been done then it will break that means all the below statements will be skipped next so let's suppose that neither i'm giving one nor two if i'm giving some other value let's suppose i'm writing here dollar x is equal to five then i will create here default and inside default whatever the statements are there that will be executed so this is the basic idea now let's see the practical example of this so what i will do first i will create a variable so i will write here dollar x let's suppose i will give here the value as 15 and after that i am writing here switch and inside this switch i will pass this variable dollar x and now what i will do i will take here case so here i will take case 15 right and inside this case what i will do inside this case i will write here echo i will write the number is 15 and then after this i will write here break and then i will write here case let's suppose 14 and let me copy and paste the same thing here so ctrl c and then i will write here ctrl v now i will take one more case default so inside this default i will write echo other value now what i will do i will execute it so let me save and now if i'm executing it so you can see that on execution i'm getting the number is 15 right why because i have given the variable here 15. now if i'm changing the variable from 15 to 14 so here you will see the key is 14 right it's matching so it will give the number as let me write here 14. now after saving if i'm executing it then you will see the number is 14. similarly for default also if i am giving some other value let's suppose 23 then you will see i am getting my output as other value let me execute here so you can see that other value so this was about switch case now let's see what is loop so loop is a repetition of a sequence of instruction to reach a certain condition right so generally we are having two types of loop first one is for loop and another one is while loop right so let's see the syntax of for loop how does for loop work in php so here if i'm writing here for and here this is the initialization part right so for loop is having three parts the first part is the initialization second one is the condition and the third one is the increment or decrement so let's create a variable so here i will write a variable dollar a and i will assign it to the value 0 right so this is my initialization part now i will write here condition so let's say the condition that this variable is less than 10 right and after that i can give the increment or decrement now i will give here the increment so i will write here dollar a plus plus right now inside this for loop what i will do i will write here statement right so i will write here echo and then i will write here dollar a right so i will getting the value of a so how does exactly for loop work so here you can see that a is equal to 0 this is my first part of loop second it will check the condition right is 0 is less than 10 yeah this condition is satisfying so it will print 0 so this will be my third part so it will print 0 right now after that once it will print 0 now it will go for update right so so after updating the value will be 1 now once again it will check the condition is 1 less than 10 yeah so once again it will print 1 similarly after printing one it will go for update so the new value will be 2 is 2 less than 10 yes once again it will print 2 similarly it will go 3 4 5 6 7 8 let's suppose here if i am getting the value as 9 right so after getting 9 it will go for the increment so here the new value will be 10 right so it will check once again condition is 10 less than 10 is this condition is true no so the loop will end so this is the working of for loop now coming to the while loop so it is having one control condition and will execute till condition is true now let's understand with example so here if i am creating a variable and i will assign the value as 0 here now what i will do i will put a condition so i will write here while loop and here i will put the condition is less than 5 and inside this i will write echo and i will write dollar array right and then i will do the increment that is post increment here so you can see that my value is 0 so inside while loop you can see that 0 is less than 5 right now this condition is satisfying so what it will do it will print 0 and then after that it will go for the increment so my new value will be now 1 right so now once again it will check 1 less than 5 right once again it will print 1 then there will be increment my new value will be 2 is 2 less than 5 yes once again it will satisfy the condition it will print 2 now there will be again increment in my value new value will be 3 3 less than 5 i will get 3 similarly i will get 4 now once i am getting 4 after that you can see that there will be increment in the value and my value will be 5 here right so once again it will check the condition is 5 less than 5 no this condition will not satisfy so i am getting the value as 0 1 2 3 4 right so this is the logic of while loop now let's see in the practical example so let's start with the for loop let me comment it down i will write here for loop so for for loop i will write a condition simple for and inside that i will create a variable and i will assign it to the zero and after that i will give the condition and let me give the condition as seven that's a is less than seven now i will give the increment so i'll write here dollar a plus plus and inside this i'll write echo and then i will write simple dollar a and after that as you know this is a loop right so there will be a continuation so i don't want the value to be printed in the same line so that's why your light once again echo and inside that i will write brtag so i will write here br now i will do the execution so before execution let me write here this now let me save it and if i'm doing execution then on execution you can see that i am getting the value right so this was all about for loop now let's see about while loop how does exactly why loop work so for while loop what i will do let me comment here while and inside while loop now i will create a variable and now i will write while and inside this i will put the condition so i'll put the condition as dollar a is less than seven and inside this condition i will write echo and then i will write dollar a and after that i will write echo br and after this i will do the increment so what's the condition for while loop until this condition is true it will run right so let me save it and execute it so on execution you can see that i am getting my values from 0 to 6 so this was all about the basic idea about foreign while loop so the next topic that we are having is operators so we are having different types of operators starting for arithmetic operator so let's see what is automatic operator so automatic operator deals with the addition subtraction multiplication division and then modulus and this is the exponential so now let's see this means in php is a division right and division will give you the question and then so this is a modulus operator so modulus operator will give you the remainder right whereas division operator will give you the question now next we are having relation operator right so this is a less than this is greater than less than equal to operator greater than equal to operator this means equal to and this means not equal to right next we are having logical operators so in logical operators we are having and or and not so this is a representation right next we are having bitwise operator so bitwise operator this symbol means we are having zor the name of the symbol is or then we are having and or and this means shift left right whereas this symbol greater than or greater than represents shift right now we are having assignment operator a segment operator means assigning the value if i am writing here this is a variable in php and if i am writing this that means i am assigning 5 value to this variable so this is an assignment operator next so now what do you mean by plus equal to so let's take an example if i'm writing x plus equal to y that means x is equal to x plus y right similarly if i'm writing minus n equal to that means if i'm writing x minus equal to y that means x equal to x minus y so in this way this assignment operator work right next we are having increment and decrement operator so here i am having plus plus that means increment and minus minus this is in decrement right okay so this was the overall concept of operators so even if you are going for multiplication if i am writing here x and then s trick is equal to y that means i am doing multiplication that is x equal to x into y similarly for division as well as modulus so now let's see the practical example of operators so let's start with different types of operator so the first operator that i will start with arithmetic operator so i will first comment it down so i'll write here earth matic operator so here in arithmetic operator what i will do first let me create a variable so i will create a variable here i write dollar variable 1 and i will give value as 5 and then i will write here dollar variable 2 and then i will give the value as 2 now i will perform addition so i will write echo and here what i will write inside this i will write echo the addition the addition is and then i will write here dollar variable 1 plus dollar variable 2 now what i will do i will execute this but before executing i will write here dot so here dot is again my string operator is there right so dot will concatenate so let me save it and now if i am executing then you can see that i am getting the addition is seven right so this was about the addition now let's see subtraction multiplication division and modulus right so what i will do i will just here copy and paste so i will use ctrl c and ctrl v and here i will write instead of addition i write subtraction here i will write multiplication then similarly for division and i will one more time i will copy and paste it and then i will write modulus okay so here instead of addition i will write subtraction that is minus multiplication i will use asterisk and for division i will use slash and for modulus i will use the remainder operator right so i don't want the values to be in the same line so what i will do here i will write here echo and then i will write vrtag inside echo and now let me copy and paste it so i will paste it after each operator and let me save it and now if i'm executing you can see that i'm getting the value the addition is 7 the subtraction is 3 i was having two numbers right 5 minus 2 will be 3 multiplication will be 5 into 10 and division will give you the question right so 5 by 2 will be 2.5 and the modulus operator will give you the remainder so if you're dividing 5 with 2 you'll get reminder as 1 so this was all about arithmetic operator so now after arithmetic operator we will see the next operator that is assignment operator so once again i will comment it down and i will write here a segment operator so what i will do here i can create one more variable let's say i am writing here dollar variable and here i can assign the value of this variable right dollar variable one so what so dollar variable one value is five right so five will be assigned to this variable so this is an assignment operator now let's perform some operations so i will create one more variable dollar variable 3 and here i will assign the value of dollar variable 2 so basically what i am doing so here my variable will carry the value 5 that is integer value and variable 3 will carry the value of variable 2 that is 2 right so this is the assignment operator now after creating this two variable what i will do i will write here dollar variable and then i will write here plus equal to 1 right now what will happen this means variable is equal to variable plus 1 right now if i'm writing echo let me write here echo and here i will write dollar variable and now if i'm executing it you can see that i will be getting the value as 6 right so why i am getting the value as six let's see what is exactly dollar variable dollar variable is equal to variable one right and variable one value is five so five will assign to this variable and here so what do you mean by this thing so this means that my dollar variable is equal to dollar variable plus 1 so 5 plus 1 will be 6. now if i'm printing my variable so i will get the value as 5 plus 1 6 right similarly i can perform several more operations so i will write here dollar variable and then i will write minus is equal to 1 and then i will write here echo and then i will write a dollar variable but before that let me write here echo br so that i can get the value in next slide okay so after this i'll write this now let me save it and if you see i'm getting the value as 5 right similarly you can perform for other operations also let me show you instead of this if i'm writing ctrl c and then ctrl v and here if i am giving multiplication and then if i am printing let me copy and paste this br and after that i will write here so here what do you mean by this this means dollar variable is equal to dollar variable into 1 right and after execution you can see that i will be getting the value as 5 and this is my output so this was the basic idea about assignment operator now let's see some more operators so now let's see increment and decrement operator so let me comment it down i will write here increment and decrement operator so here i have created a variable whose name is variable 10 and inside that i've assigned the value as 14. now what i will do i will do the post increment so i will write here dollar variable 10 and then i will write plus plus and after that i will print the value of this variable so i'll write echo and then i will write here dollar variable 10 so if i'm executing it now so before execution let me write here echo br let me save it so if i'm doing the execution now you can see the value i'm getting as 15 right so this is the post increment so my value was 14 right and then after that i have done the increment now we'll see the example of decrement 2 right so what i will do now i will do the decrement so i will write here variable 10 and then i will do minus minus and before that i will put dollar here and if now i'm printing this let me put here br after i will save it so let me do the execution you can see that i am getting 14. so i have showed you about post increment and post decrement so what do you mean by post increment so in post increment what it will do first it will print the value then after that there will be incrementation similarly for post decrement first it will print the value then there will be a decrement i will show you the example here i have written that dollar variable 10 minus minus so if i write here echo right and let me write here vr also after this similarly if i am writing here echo and let me write here br2 and now if i'm saving and executing it you can see that these are the values that i am getting i will tell you how let's see this so here you can see that variable 10 value is assigned as 14 right so as i told you that if you are doing the post increment right so first it will print the value and then there will be increment so here i am writing echo so echo will display the output so here i will be getting as 14 so if you see here i am getting as 14 right and after that there will be a increment in the variable so if i am printing then variable then there will be increment and then i will be getting 15 so you can see that i am getting 15 here now so 15 i got it now what i am doing i am doing here post decrement so here i got the value as 15 so first it will print 15 and then there will be decrement so here i will be getting my output as 15 and then i will get my final output as 14. so if you see here i'm getting 15 and 14 right so always remember post increment as well as post decrement so first there will be the print of the same value and then there will be increment as well as decrement right so this was the logic similarly for the pre-increment there will be a prior increment in the value right so this was the basic idea about the operators so next we are having the comparison operator that we will see in loop so this was the basic idea about operators so the next topic that we are having is strings right now you might have a question yeah we have already discussed about the string variable and we also know that what is the string right but i want to show you some functions that we can use in string to manipulate it the first function that we are having is string length so let's suppose that if you are having any string let me create a string variable so i'm writing here dollar string and here inside double quotes i will write let's say gaurav so if you want to calculate the size of this string variable then you can use string length function so it will give me the size of an string right now the next function we are having is string word count so if i'm writing here let's suppose that i'm making one more string variable a string one and here if i'm writing great learning so you can see that i'm having great learning so there are two words so if i'm writing here string word count so i will get two in my output next string reverse yeah in php we can do the reversal of string but in java there is no such function is there where we can do directly reversal of wasting right but in php it's possible now so let's suppose that this is a great learning right if i want to do the reverse of the string then i will write string reverse so other than these three there are some more functions that are used in string we'll see each of them in practical example so now let's see some functions in a string so what i will do first i will create a string so i write string variable dollar string and i will assign the value here great learning so this is my great learning let me give space in between so this is my string variable right now after this what i will do i will put this inside a syntax of php and then let me close it so if i want to know the length of this string so i told you the function the function is string length right and inside this i will put the parameter string so and now so if i want to display the output on the screen then i will use echo function so inside echo i will write this thing right now if i'm executing it so on execution you can see that i am getting length of a string as 14. now so this was about the length of the string now what if i want to know the number of words in a string right so here you can see that we are having two words in a string so for calculating this i will write once again echo and then i will write string word count and now inside this what i will do i will write once again the string variable and if i am executing it so on execution you can see that i am getting 142. so why i'm getting here 142 because i didn't use the br text so let me write there be a html tag so that i can get the value in the next line right so here i will write echo so now i will write here br so let me execute this so i will just save it ctrl s and now i will execute it so now after execution you can see that i am getting the word count in a string that is two right because great and learning are two words now let's see another function that we are having so i will once again copy and paste this vr thing and now after that as i told you that we can also do the reverse in a string in php right so what i will do here so i will write here reverse function so to write reverse function i will write here string reverse and now inside that i will put my variable that is string right so i'll write dollar string here and now if i'm executing once again let me save this so on execution you can see that i am getting the reverse of great learning right so yeah so these are some functions that we can perform in strings so the next topic we are having is functions so what is function function is a block of code that runs on invoking or calling right so let's see the syntax of function if you want to create a function first i'll write function and then i will write function name so let's suppose if i'm writing here at tech so this is my function name and inside this i can write my statements and then i will close this function right so as i told you function is a block of code that runs on calling or invoking so then how to call a function so if i want to call a function then i will write outside the function edtech that is nothing but function name so i will write here function name to call the function and function will be called so if i'm writing a red tech so it will jump and it will see a text so whatever the statements are inside the function it will execute right and why do we need function and why do we use function because instead of writing similar code again and again we can create function and then we can call it right now let's see a practical example of function so i will write here code php and inside this i'll write function and i will give the name of the function as edtech and inside this function i will write here echo and then i will write simple welcome to create learning welcome to great learning and then this is my function right so i've created my function now i will call this function so here i will write simple edtech with the function name now let me save this and close this php now if i'm executing this then you can see that i am getting welcome to great learning so this is the basic idea about function so next we are having function arguments so information can be passed in function through arguments so if you want to pass any information in function then you can pass through it arguments right and also remember that call by value and call by reference is supported by php now let's see a demo of function arguments here this is my syntax of php and inside that i have created a function whose name is student and inside this i am passing a variable right whose name is dollar name and inside this i am writing echo hey and then dollar name right so as i told you that if you want to run a function then you have to call it so i will call the function with the function name so student and inside that i will put parameter as tony so instead of name tony will be there and it will print and give me hey tony similarly once again i am calling with admin and gorop similarly my output will be coming as hey admin and hey gaurav now let me show you with the practical example so now what i will do here i will first create a function and after creating function i will give the name of function as student and inside this student i will give a variable let's suppose name and after that inside this function i will write echo and i will say hey or you can see i will say the name is and then i will write here dollar name and after that i will write br so i will write here br and then i will close it now after this what i will do as i told you that if i want to call a function then i will write function name and inside that i will write tony let me copy and paste and then i will change the name here admin and here goeroff let me save this and if i'm executing it now then you can see that i am getting the name is tony the name is admin and the name is gaurav so this is all about function arguments now we will see call by value and call by reference so what do you mean by call by value so in call by value actual value is not changed even though there is any modification inside the function so this is my function and here i am changing this variable to gl right but my actual value is great learning right even though there is any modification inside the function then also my actual value will not change so if i print here i will get my output as great learning right let's see what is called by reference so here actual value will be changed if there will be any modification inside the function right so for call by reference here i will write ampersand right so you can see that here my actual value is great learning right but there is a modification i am doing here inside the function and i am writing here gl right so when you will display the output here so your output will be here as gl right because actual value will be modified if there is any modification inside the function now let's see the practical example of call by value and call by reference now let's see first call by value so for call by value what i will do first i will create a function and let me give the function name as text so i'll write edt and inside this let me create a variable dollar a and inside this function i will write here dollar a is equal to gl right now what i will do now i will create my actual variable so i will write here dollar b is equal to great learning and now after this what i will do here i will call this function and after that i will print let me save this and if you are executing it you will see my actual variable is great learning so on execution i will be getting the value as great learning so this is call by value actual value will not modified let me execute so on execution you can see that is showing great learning so in call by reference actual value will be modified if there is any modification inside the function so here you can see that inside this function we are having dollar a gl right there is a modification but for call by reference here i have to write ampersand right and let me save it so on execution you can see that i am getting my value as gl right so changes inside the function will reflect the actual variable so this was all about call by value and reference so the next topic we are having is array so what is array so array is a collection of more than one value in a single variable right so each element in array has a distinct index now in general in php we are having three types of array the first one is index array second one is the associative array and the third one is multi-dimensional array so by default if nothing is mentioned then it is considered to be an index array right so i am talking about as of now index array right so always remember that indexing will be start from zero right so you can see that in the formal definition array is a collection of more than one value in a single variable so here you can see that we are having multiple integer value here and as i told you the indexing will start from zero so this is at zeroth position this is the first position this is the second one third one and similarly fourth one right and if you want to access any value then you can access it through indexing so coming to the third point here it is written that any elements in an array can be accessed through indexing suppose that if you want to print 11 then you can write it through indexing now let's see the creation of an array so here in php the function that we will be using to create an array is an array function right so here this is the basic syntax of php and this is the variable that i have created for array and inside this variable let's suppose that if i'm creating any variable a then i will create an array function and inside this array function i will store multiple values right suppose that if i'm writing here great here i'm writing learning okay so this is my array now as i told you that if you want to know the learning value then it can be fetched through indexing so what i will do now i will write here simple dollar a that is my variable and as i told you that indexing will be start from zero so this is a zeroth position this is my first position and if i'm writing here first position and before that if i'm writing here echo then you will see that i will be getting my output as learning so in this way we can get the value through indexing so the value can be fetched using indexing so this was the basic idea about an index array now let's see an example so let's see the example of index array so let me create a variable here so i'll write dollar a and i will create an array function and inside this array function what i will do i will write here let's suppose welcome to great learning so here this is my array and it's containing a string values multiple string values now if i want to print suppose learning so as i told you indexing will start with zero position right so at learning my position will be three right zero one two three so what i will do here now i will write here echo and simply i will write dollar a and then i will write the indexing position that is three and let me save it and on execution you can see that i am getting my output as learning so this is a basic idea about indexed array so after index serial now let's see associative array right so before moving to associative array here we are having count function right so count function will give you the number of elements that are present in array so here you can see that we are having three string values so as i told you that count function gives the number of elements so here the number of elements are three so if i'm writing echo count and inside that if i'm writing variable then it will give me my output as 3 right so yeah coming to the associative area elements are associated with is equal to and greater symbol so basically associative arrays are used to store the key and value pair right so here you can see that we are having two ways to define an array the first way is i will create a variable and then i will write array function and inside this function i will write key and its value so tony is the key here 96 is the value similarly admin and gaurav so this is the first way now moving to the second way i will write the variable name and inside that once again i will give the key and i will assign the value inside that key so 96 is assigned similarly once again i will write the variable name another name admin and then value is assigned to this similarly for gaurav also so this was the basic idea about associative area now let's see the practical examples so now let me create the associative array so i will write here dollar marks this is my variable and inside this variable i will give the name let's here take the name of tony and then i will assign the value here 97 similarly i will write here this same variable and inside this i will give the key as an admin and then i will write 96 so let me write this variable again and i will right now got up so let me assign here the marks as 89 now after this what i will do after this i will write just echo and then i will simply write dollar marks stone here let me copy this and if i'm writing here and if i'm executing it let me save it so on execution you can see that i am getting the marks of tony as 97 right i can also write in another way i can also write the marks of the toonie i will write here the marks obtained by 2d is and now i will concatenate it so i will write here dot and let me save it and if i'm executing now you can see that i'm getting the marks obtained by tony's 97 so this was all about associative array so next we are having multi-dimensional array so multi-dimensional array is array of arrays why i am telling this let's see this is a variable and here inside a array i am creating array you can see that i am creating multiple array inside an array right so that's why i'm writing it's an array of arrays right and multi-dimensional array can also be represented in the form of matrix how can you see so this is one two three so let's say that this is a student id right so the student id and this is the name of the student and this is the marks scored by the student so this can be represented in the form of matrix right so we can have three rows and three columns right one two three then i will write here tony gaurav and edwin 96 92 86 so these three are rows and these three are columns so it can be represented in the form of matrix form right so this is the basic syntax of multi-dimensional array right now let's take an practical example of it so now what i will do first i will create a variable so i will write here dollar array and inside this variable i will create array function and inside this array function i will create array so as we know that multi-dimensional is a array of an arrays so i'll write here array and inside this array i will write ram shyam and then manish and then let me give quotes here and after that i will create one more array and here also i will give let's say i'll write here gaurav then i will write here tony and then i will write here adwin if i want to display the information of this array so what i will write i will use here print r method and inside that i will write my array name let me execute this now i will save this so on execution you can see that information has been displayed and also you can see the indexing position here in the output so this was all about arrays if you haven't subscribed to our channel yet i want to request you to hit the subscribe button and turn on the notification bell so that you don't miss out any new updates or video releases from create learning if you enjoyed this video show us some love and like this video knowledge increases by sharing so make sure you share this video with your friends and colleagues make sure to comment on the video any queries or suggestions and i will also respond to your comments
Info
Channel: Great Learning
Views: 4,108
Rating: undefined out of 5
Keywords: php crash course, php crash course for beginners, php course, php course for beginners, php tutorial, php installation on windows 10, php comments, php print, php functions tutorial, php array, php loop
Id: aPZmvem0gqQ
Channel Id: undefined
Length: 90min 16sec (5416 seconds)
Published: Sun Sep 19 2021
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.