PHP Programming Tutorial For Beginners | PHP Tutorial For Web Development | PHP Training | Edureka

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
[Music] hi guys my name is Aria and I welcome you all to this PHP tutorial so in this PHP tutorial we'll be covering what is PHP why should learn PHP in 2018 and then we will go over the basic fundamentals of the programming language of PHP so without much further ado let's get started so let's cover the basics first now so what exactly is PHP well PHP as you guys already might know is a server-side scripting language which is a very powerful language for making dynamic and interactive web pages now before we move ahead let me tell you that PHP actually stands for hypertext preprocessor which is a recursive acronym for PHP then it is also open source and free to use and even though it's a language that can do almost everything a programming language can do it is mostly used for server-side logic which means when you go ahead and click on that login button on your facebook login page the logic that lets you allow to get into your account is what PHP is doing ok so let's go ahead and see what exactly you can do with PHP so these are the four major things that you can do with PHP firstly you can create dynamic and beautiful web pages you can collect data from a form that has been created in HTML you can use it for data encryption and last but not the least out of the many functionalities of PHP you can use PHP to create a simple crud application which stands for create read update and delete ok so that tells us what you can actually do with PHP now some of you might be wondering why should I actually learn PHP in a year like 2018 where there are multiple alternatives available the first of all you must consider that PHP is widely used and extreme flexible language it has found users for small websites from ranging to small businesses for bicycles and stuff and even big businesses like Wikipedia and Facebook are using it so when you know that something like Facebook which is a tech child is using PHP for its backing it's a pretty solid language that can handle millions and millions of data now PHP is also very compatible with multiple server types like Apache and other TLS servers it is also compatible with multiple database types like PostgreSQL MySQL and no SQL then to top it off it's free to use and it's extremely easy to learn now if you are at riving web developer or you want to get into web development PHP is surely the way to go if you want to have any success in this field okay so now that I've told you why you should learn PHP what importance PHP has in 2018 let's go ahead and go through some of the basic fundamentals of PHP now now don't worry because for the next five minutes I'm just gonna be showing you slides based on the syntax of PHP we are also going to be coding our very own PHP scripts at the end of this video so if you think this video is gonna be all slides and no code that's completely wrong so let's go ahead and get started it's the first thing that we are gonna learn in PHP is how to declare a variable now if you don't know what a variable is because it's probably you're coming from a non computer science background with no prior experience and programming well available is a name given to a memory location on your RAM so that you can store a certain value in it now consider this blue thing out here the RAM that is in your computer and we want to store this age inside so we are going to name this memory location age and the value it's going to store is going to be 22 now how you do that in PHP is basically say dollar sign and then the name of the variable which is age out here and then you assign the value with the equals to operand and then you go this value is 22 okay so that was variables now aside from variables we can also define constants and constants are things that don't change their value over time so something like the value of pi is a constant so to define a constant we use the defined keyboard and then we set the variable name or the constant name in this case and then the value of the constant which is 3.1415926 in this case okay now there are five types of data types and PHP firstly it's integers which is basically a number without any decimal point secondly is float which are numbers that have multiple decimal points in them next strings which is basically a sentence or array of words then the fourth type is boolean which is a binary of true and false and the last type is undefined then that is when you do not actually give any definition to available or a constant for that matter okay so we also have arrays in PHP now if you don't know what an Ari is well it's a data structure that contains a list of elements and most of the time these lists of elements are common in nature now these elements are mostly of the same data type and talking in computer science terms so an array of integers will mostly carry only integers now I've already defined an array just for an example so first of all you define an array like this in PHP you say the are a name with a dollar sign then you use the array pre-built function and then you can put in your array elements out here after the words a class Marcin KitKat which are some of my favorite chocolates next we have also functions now functions are of two types predefined functions and user-defined functions predefined functions or you come pre-built in PHP so something like the date function which we will be seeing its usage while we are coding some PHP of our own is a predefined function and I use the define function is something like this which are wrote out here so I've made a function out here which adds two numbers and returns it now these are the power meters that it takes now number one and number two are the parameters and odd numbers is the name of the function now functions are a beautiful way to actually reuse code and make your code much more modular next we also have conditional statements in PHP now there are three types of conditional statements first is the if statement then is the if-else statement and then is a switch si will go through all of them when we are actually coding now this is just for the theoretical part so if statements or conditional statements for that matter are used when you need to perform a certain condition in your code so suppose you were saying that you're making a application for betting now in a betting situation you are normally comparing who won the bet right so this is a good example of when you would use a conditional statement now we also have iterators in PHP there are three kinds of iterators or loops in PHP the first is the for loop the second is the while loop and the third is the do-while loop now iterators are basically used when you need to actually repeat a specific block of code again and again in your software so we'll see how we do that so this is how you actually define a vile loop in PHP you go vile then the condition of the loop and then you're looping code now vile loops are entry control loops as you might already know and while loop always checks the condition before actually executing the loop code now the same can be said for a do-while loop which is an exit control loop now this is how you define a do-while loop you go with two keyword then the loop code and then the Vile's condition now you have to realize this is called an exit control loop because the condition is checked when exiting the loop so the loop will for sure at least execute once then we also have the for loop which has three parts versus the beginning or the initialization part where you initialize the iterating variable then the condition where you are checking for a condition where you can exit from the loop and then the step which is the steps that the loop will iterate through so if you say I equals 2 I plus 2 for example this I will always increase by 2 and inside the brackets you are going to specify your looping code now you want to iterate throughout and the last thing that I want to cover for the basics is switch statements now switch statements are also a type of conditional statements and are used to compare an expression now in case we are trying to compare if expression is equal to case one case two or a default case where it doesn't match case one in case - so if out here expression matches case one this code of block after the colon of case one is going to be actually executed if it doesn't match anyone of case one or case to the default block is executed and then the switch block is completely exited so that was all about programming and how stuff is actually generalized and initialized in PHP now that was all the basic syntax of PHP now let's get into the beef of PHP by actually coding some of our own okay now if you remember I had told you guys that PHP is a server-side language so this means to actually deploy our PHP scripts we need a local server now for my local server I have already installed samp and I'm serving an Apache server on my computer locally and you can do the same by just downloading zamp and going through the configurations I'll let you figure that out on your own so let me just show you what I've created so firstly I have my Apache server running as you can see on port number 8 0 443 and if you go into my files you'll see that I have an index dot HTML page created so this is basically a form now let me just show you this form so this is what the form looks like and we are going to be using PHP to gather some data from this now if you remember I had also told you that PHP is a fantastic language for gathering form data from HTML so let's go ahead and see how we can do that ok now I'm already created this script dot PHP let's go ahead and open it with sublime text now let me just delete everything let's save it and let me also show you this index dot HTML so basically it's the form inside the table and it's a student registration form just like I showed you so first of all PHP is embedded in normal HTML codes so let me just show you how to do that so you first of all create your HTML boilerplate and let's say this is called PHP demonstration right now to begin your PHP code all you have to do is open up your PHP tag which goes something like this and you close off your tag like this all your PHP code is going to come in between these tags now let's firstly show you how to comment in PHP so this is how you post single line comments this is also a single line comment and this is how you post multi-line comments now if I will just press ENTER you'll see that the comment is not broken out okay so that's how you do multi-line comments let's go ahead and dream that my lines okay so that was how you comment in PHP now let's do a simple hello world in PHP too so to print out stuff using PHP you go echo and then you just use double quotes and say let's say h1 hello world so since our output is going to be on a web page we are gonna use markup to actually output our stuff so you say h1 you close off your tag and all your PHP statements are going to be ending with a semicolon which is going to be your statement terminator now let's go ahead and open up a localhost and you just go /script start PHP okay so our script dot PHP is being served on our localhost and as you guys can see it's printing out how the world now if I would have just changed this to a P tag and a P tag here you would see the difference so see our hello world has now changed into a paragraph okay now I had also spoken about predefined functions and date is a very much use predefined function in PHP so you can print out the date using PHP so let me just tell you some of the formats you can print out your Dayton so let me make a multi-line comment first so these are the parameters you are normally going to pass in to your date function let me just list them out for you so firstly you can say H to print out your date and 12-hour format you can also go capital H for 24-hour format then you can use the I flag for the minutes the S flag for the seconds the U flag for microseconds then for a will give you lowercase or pm10 capital I will give you full text for the day then capital F will give you full text of the month and G will give you the day of the month and capital S will give you suffix for the date like 1st 2nd or 3rd or something for something like that and Y will give you the year in four digits right so let's keep this in mind when printing out our date now to print out a date you can simply go echo and say date because it's an inbuilt function and you are just gonna pass in these parameters that I just showed you to print out whatever you want so suppose we want to print out the R's in 12oz format we also want the minutes we also want the seconds we also want the microseconds and let's say we want the full text of the month I also want the full text at the day and that's it let's save this let's serve it now ok so you see it shows according to my computer it's October 1st and this is the time up till whatever we had specified so that's how you print out the date using PHP now I had also told you that PHP is a fantastic language to collect form data now I've already created a form out here and that can be served on our localhost so we have the student registration form why are we taking this to rename the grade that they're in the section that they're in and also the class teacher's name now in our index you see that these have already been given a name this name attribute is going to be used in PHP now you can access the values from the HTML that called this PHP script to execute putting the names assigned in the HTML in single quotes now these are normally stored in an array called post so let me show you how that's done so first of all let's remove all this now let's create a few variables so to create variables you see use a dollar sign and say student name that is going to be the name of our variable now our stuff is going to be stored in the post array this is going to be called student name in the HTML and we always have to end our PHP with a semicolon now let me just copy this out a few times so first of all we have grades then we have section and we also have teacher right now this is called create in our HTML this is called section in our HTML and this particular thing is called teacher name in my HTML right okay so now to print out stuff let's see echo first of all we are going to be saying h1 student information right then we also want to echo whatever student information that we've already collected now we can use the dot operator or the full-stop to actually concatenate a variable with a string so this is how you do it so suppose you want to say student name is so space then dot and just specify the name of the variable that actually contains the student name we just do the name in this case then you can also say he is in whatever grade that you want to put him in he's in grade and let's put a space and then the dot operator and you can say something like so basically we're going to say create out here then you go echo and then you want to print out the section he studies in section and space and then the dot operator and you want to say section and echo we also want to print out his teacher is taught by the teacher by rather just leave it a space and a dot and then teacher right now every time somebody submits a script our PHP is going to be run because that's the action that we have specified and the method is going to be post so let's save this let's reload our page and let's put in some data so my name is aria Paul I'm in the 8th grade which is section a and my class teacher's name is mr. Roy so once you hit submit okay so it says unexpected echo expecting so on line 18 so let's see line 18 okay yeah so see I'd forgotten to put a semicolon here so that's why he got that head of let's go back again let's submit it now you see the student name is our appalled he isn't create it he studies in Section E and he start by mr. Roy it's now that was all in one line and that kind of looked a little ugly so all you have to do is just say slash BR let's copy that and put it everywhere it's pretty here too and let's put it here too let's save it let's reload it ok so as you guys can see just ignore this part the student name okay let's go ahead to our localhost and just given some student names so Aria in grade 8 in Section E and taught by mr. Roy so you submit that and now we have our information in a neat manner so our student name is re Paul he's in grade 8 he studies in Section E and he start by mr. Roy nice so that is one way to collect data from a form now let me show you some other way that you can actually output this let's remove this for now let's see you can say let's create a string and now you can use the EOD method so for that you go you OD the student name is student name and he or she is in this grid in section and then the name section and he or she is taught by teacher and to end your end of document all you have to say is yo D and then the semicolon let's just reload this your localhost and that's putting some values now you can use the end of document to actually say output everything in one string then all you have to do is go ahead and echo your string so you say echo string and you end your statement let's save this now let's go back to our localhost let's input some data and let's see if it actually gets output it's the way we want to do so as you guys can see it's saying to name is Arya and he or she is an eighth grade in Section E and he or she is taught by mr. Roy now that's a very intuitive way of actually outputting your stuff using PHP so that's the EOD method okay now let me show you how to define constants so let the stuff be here for now now let's define a constant you can use a define keyword for that go define let's say you want to define a thing called pi and it's gonna have a value off three point one four one five six right let's not forget a semicolon now do just output this you want to say the value of pi the dot operator and all you need to say is bye let's save that okay so now you see just ignore all this part because it says undefined on line ten because this is not needed anymore let's comment that out save it again okay now you see that the value of pi is 3.14 156 so that's how you define a constant and that's how you output a constant now we can also do simple arithmetic operations in PHP so let me just show you how to do that well echo let's see you can say five plus two equals mmm you put the dot operator and then you just say five plus two so let's see how that works so five plus two equals seven now let me just show you all the different types of operations that you can do so firstly you can do - subtraction you can do multiplication let me just show that with an X instead of a star and you can do division and you can also do modulus modulus means it'll give you the remainder so you go five minus two if I x - 5 divided by two and five modulus two let's save that let's run that ok now this will all be printed in one line so to avoid that let's give them a break line so you say PR this is copy that and paste it everywhere so now that we've pasted everywhere save it let's run it and as you guys can see we have the output so 5 minus 2 is 3 5 x 2 is 10 5 divided by 2 gives 2 point 5 and 5 modulus 2 is 1 now if you realize PHP automatically realizes that this is a float that is because it's an interpreted language it's a scripting language ok ok so that was all about arithmetic operations now you can also cast from one type to another so let me just show you how that can be done so let's say you want to print out 5/2 as an integer now you can also cast from one type to another in PHP so suppose you wanted to print out 5/2 as an integer all you have to do is say in teacher before your output and now this will be actually converted into an integer so now it says 2.5 and now watch as I reload it says 2 so that's how you can convert stuff to an integer or back and forth now you can also use shortcuts when performing an operation so suppose you wanted to say 5 plus 5 let me just delete all this first of all let's comment that out and I want to say 5 plus 5 so you could set just say 5 plus equals 2 right let's say that now you can also use shortcuts when performing operations on the same variable so let me just comment out the shortcuts for you first so you can use the shortcuts like these so plus equals 2 or you can use minus equals 2 then you could use multiplication UCLES 2 or division equals 2 so let me just show you how that's done so let's just create a variable called round number and this is going to be equals 5 and we want to increment this by 5 again so all you have to do is say echo ran um say plus equals five so this will just add five to a random number no only half to do is just open this in your PHP so as you guys can see random number equals ten now you could also do multiplication so now this will output 25 or you could do division so this is print one are you gonna do modulus this is bring zero okay so that's how you shortcuts in PHP now you can also use increment and decrement with the shortcut so let me just show you how that's done so you go echo and you say plus plus run num so let me just show you the difference between post increment and pre increment which is a pretty important concept in computer science so you say plus plus R and num let's not forget to add the line break yeah so that's adding the line break and let's copy this down and let's do so this one out here is called pre increment and this is called post increment now pre increment will actually increment the number of a job before printing it so let me just show you how that works undefined variable run run um okay okay I have to use normal you I'm sorry I got the variable name wrong okay so random equals six and since it's already becomes six this should have actually printed seven but since it's a post increment it'll print out the number and then increment it now if I were to just go ahead and echo Rand num you will see that it's already in turn two seven okay sorry I got the name of the variable wrong again and this should be equal to seven yep so that was just the basic difference between pre increment and post increment now you can also store the reference to an operator or a variable and you can do that with the ampersand sign so let me just show you how that's done remove all this actually let's keep this part like it's been reusing that part later on now you'll see let's say we're gonna say this is a reference to a number and we need a random again so R and num it's gonna be equals to five our reference to number is gonna be an percent and then the name of the variable so reference number is actually a reference to run num now if you were to go ahead and change random equals 200 now and you were to echo out the reference to a number so let me just show you how that's done so ref to num is going to be equals to so this square is going to be equals 200 now okay I think I missed something again yep I missed this and reference number has been successfully changed to hundred now what have I changed round number two is what reference to our number is going to change to so this is basically how pointers also work in different languages okay now let's move ahead with conditional statements so I had told y'all that conditional statements are used to decide a certain condition so let's keep two variables so let's call this min now and let's call this max so max is obviously gonna have a bigger number now let's compare if that's a min is less than max what we want to do is say echo let's put an h1 Max is the biggest number okay so this is one form of if statement let me just run that okay line 22 yep I forgot my semicolon again I'm so sorry I'm very bad with semicolons yeah so it says max is the biggest number now let's say let's change min to 10 and let's change max to 5 now you see that nothing is actually being printed because this condition is not being met but if we go else we can say echo h1 max is not the biggest number let's close off our h1 and let's also not forget the semicolon this time now you'll see it's gonna print out Max is not the biggest number which means that the else block got executed so this is how you actually use conditional statements in PHP okay so let's go through some more conditions now elsif is used when you have to check more than one condition now let me just show you how that's done okay let's remove all this now let's say you went grocery shopping and you want to buy a bunch of chocolates or let's keep them fruits so you wanna buy oranges and you bought around 40 oranges okay and you also taught that um let's buy some bananas because they're full of potassium and I really need them so you got 35 bananas now the grocery store has a cash back on their bill so let me just put out the grocery store cash box no let's say if orange is greater than 25 and now they're also stuff like this way if you are used programming let me show you andin is used to actually show the ant situation which is basically the and gate then you can represent the or gate through pipes and you can also do it with noir which is basically negation so these are the type of binary operators that we have and you can use them in PHP too so let me just show you conditions so let's put a condition also that banana has to be greater than 30 now if you guys are looking at the code you must have already realized that this is the block that is actually going to be executed so you say 25 percent cash back on the bills let's end our statement but I also want to show you how to put multiple stuff so you go elsif let's just copy this down so if oranges are more than 30 and bananas are more than 35 let's say you're gonna have a 15 percent cash back on the bill so echo 15 percent cash back [Music] let's put another condition to check so if oranges are more than I rather let's see you can also say something like if oranges are less than 5 and bananas are also less than 5 you can say that's gonna be a 1% cash back on the bill and then you can finally say else that's gonna always be a final statement you can say no cash back on the bill now forgotten my semicolon here here so let's just execute this for the sake of executing ok on line 28 28 undefined variable Orange okay orange had a copy oh so that's why this is giving an error save that ok orange is this make it orange out here and as you see our first block of code got actually satisfied so oranges are definitely more than 25 and bananas are definitely more than 30 and that's why we get a 25 percent cash back on the bill ok so that was how you go through multiple conditional statements now you can also use ternary operators so let me show you how to use ternary operators in PHP well ternary operators are used something like this so first of all let's say max is equal to say 15 rather than 10 so it's not true if that is going to be true then our value assigned will be 15 and or the value assigned will be 10 so let me just explain how this works first we are gonna check this statement now max is equals to 15 or 10 so how is this gonna be decided if 15 is greater than 10 which is indeed true 15 is gonna be a sign now else 10 is gonna be a sign right let's save this and more echo max also echo max so max is 15 at this moment let me just make this 5 and max will not turn to 10 so that's how you use ternary operators in PHP now the other kind of conditional statement that I want to go through and we had also discussed is switch so let's say switch how you define switch now whatever is gonna be switched inside so first let's see let's call it random again random equals 5 and we are gonna switch around run no now all you have to do is set cases now let's say case 3 which case 3 what I'm gonna do is echo random number equal to the dot operator and you say random and let's not forget to put in the break and semicolon now to break out of this case you also need to use a break keyboard that's indented lines yep now let's put some more cases copy that down faces multiple times so this is gonna be case for case 596 okay so let's remove these so out here it's gonna be close tree out here it's gonna be it's gonna be equals just six now just in case nothing matches we also need a default case so case default it's gonna be let's say just copy that down let's paste it and random number no case matched so that is done let's put in a semicolon and you don't need to actually break out of case default because that's the last case and you're inevitably gonna break out of the switch statement now according to our logic case 5 is going to run okay so let's save that and let's reload ah I think a sin ty unexpected default okay so okay yeah we don't use actually the case keyboard when going with default let's save that again that was silly arrow now you can see random number is equals to 5 now if I were to go and say random number Z goes to 0 default case should be matched so you see no case matched and that's how you use switch statements in PHP ok so that was all about conditional statements and how to use them in PHP so now let's move on to iterators so let's remove this completely so iterators as i had already discussed is used when you want to iterate a block of code for yourself so let's see how that's done so let me just define a number first of all so let's say far equals 0 so that's a variable called 0 now all I wanna say vile are variable is less than 20 what we want to do is echo out variable don't forget the brakes and we also want to do increment variable so far plus plus let's go ahead and see yep we go from 0 till 19 because we said it's gonna be less than 20 now if I were just go ahead and say less than equals 20 it'll also print 20 for us yep and that's how it's done now we could use the same logic for a for loop so in a for loop all we have to do is for let's say variable equals 0 and let's say our variable is gonna be less than equals to 20 and the step of our variable is gonna be this plus plus so you could say var equals 2 VAR plus plus 1 or you could just simply say var plus plus that's the same thing now you want to increment the all the thing is done now all you want to do is set up your code that you want to show out here so you wanna echo is your variable so far and let's not forget the line break after all put that in double quotes and let's end our statement now you see it's gonna be the same thing yup so just to give you guys a difference let's print distance 10 and now we have the same thing to ten using a for loop now let me show you how to use a do-while loop so you go do and your code so and then the vile condition right so that's how it's done what do you want to do let's say we have all you want to do is echo variable and you also want to increment variable so far plus plus shouldn't be any space that's a semicolon and you want to do this - let's say variable is less than equal see that let's see yep now we have a 230 now what I want to do understand that this loop well at least execute once now let's say I think it's 31 already so this shouldn't actually execute but it will so I'm going to show you that so yep it prints 31 now since it's 31 this condition out here will return a false but since our do comes before it's always going to execute once so this is why do vials are called exit control loops okay so that was all about iterating now let's move on to arrays okay so to set an array as I just showed you I had an array of chocolates in the PowerPoint presentation that I showed you so chocolates will be equals to re and it's going to take in the members so let's say table you're on then I really love Twix Mars is also really delicious chocolate and how can you forget it clears so this is how you set up an area so to access the members of an array this is how you do it so echo let's say I love space and dollar sign chocolates so you just mentioned the index number and that's how you specify what you want to access so let's see what this prints out so it should print out I love top neuron so it prints out all I have table on now if I were to just change this to two it'll say I love Twix or I love Mars actually because two is what Marsh's so it says I love Mars and that's how you use Ares now you could also cycle through the array with the four or four each so let me just show you that so suppose you want to print out all the members of the area so you can go for each chocolates sweets and you just want to print out sweets so sweets is just a random variable which is going to be used to access the members of the array so you could say echo sweets and let's put a line break save it and it should print out all the chocolates that we've stored so toggler on Twix Mars and eclairs that's how you use the for each statement in PHP okay so in PHP you can also create key value pairs so let me just show you how to do that again so let me first delete this so let's create a student are in on so student it's gonna be re and it's going to be taken student name as the key and it's gonna pair it to student name and then we can also take the grade and pair to the grade keyboard yeah so huh that's how you do that so these have created a key value pairs so to cycle through this let me just uncomment this first remove this we are gonna be using grade and student name so let's uncomment that out save it and so what we're gonna say it's for each so student as key and value you wanna say echo you want to echo the key that's for the colon and then you want to put the value and that's it and let's not forget the line break okay unexpected to sing in line 19 line 19 what are you expecting okay I forgot my semicolon yeah yeah okay so this is what it was gonna do now so let's go back to our phone and let's say aria is an eighth grade third section and then mr. Roy at some mintus and says student name is aria and it's great is eight now suppose we had bunch of student names and a bunch of grades it's gonna print out all of them now you can also concatenate two areas so let me just create two arrays for you so let's put in the chocolate sorry again and let's put in some members so this is gonna have top drawn and it's gonna Mars and it's gonna have twigs also gonna have let's put another thing a class yeah that was well now let's also create a student diary let's remove this key value pairs to a bunch of stool teams Aria let's say prayin uh ice now and not the best friend of mine from college budget so these are just two arias that I've created and we can concatenate them very easily so to concatenate them all you have to say is let's say new re Z equals two chocolates plus student and for each let's go through all the elements so new re that's it you're just gonna call them element and you want to echo out all the elements echo element and then the line break so that looks neat let's not forget our semi colon have you forgotten semicolon somewhere else no let's comment this out because we don't need them anymore save it let's run it okay expected this on line 25 okay I forgot you and I deleted the PHP tag okay so that was a mistake okay so stopped on repeat so that was all about associative arrays and how you can use them in PHP now some of the more common array operators that are that I use are equal to equal 2 which basically checks both the arrays are of this are the same now let's see how you can do that so let's create two arrays let's say this is another array I'll just show you so you say a student and it's gonna be an array of student names so say Paul let's apron now let's create nothing called names and this is also going to be an array and it's gonna take the same things basically so let's just copy this down so if you go and say if student you go c equals two names or a quote arrays the same okay I forgot my semicolon again okay yeah that's common these out so now you see that the errors are the same now some other operators you can use with arrays is not equals to so if this is not equal to then now I will just not print anything because both areas are the same indeed and let's switch these around row let's call this Paul and it's called this Aria and let's check if they're still equal now they're not equal so this part is also known executed so that's how it's done now you can also create multi-dimensional arrays so let me just show you how to do that so multi-dimensional array so let's see it's created Oracle student just gonna say re and an array a multi-dimensional array is basically an array inside of an array so you can do that again so go re and let's say aria he lives in Bangalore and some five five is let's say a role number no you have to put a comma out here and do this again and again copy that down let's see the jeat is from Chandigarh and then we all have a partner who's from Mumbai let's give these guys some random numbers also eight and it's and re and let's so this is how you define a multi-dimensional array so let me show you how you can cycle through multi-dimensional array so say 0 and roll less than 3 because there are three characters and row plus plus and four again then you say column because 0 column is gonna be less than 3 and column plus plus now all you want to do is echo out the student of row and column and now let's separate them with commas send up okay so Arya Bangalore 5 Jeet okay so let me just show you another trick since we want them in separate lines all you have to give us a line break let's do that okay so now we have these information Arya Bangalore 5g Chandigarh 8 and a person a Mumbai 10 so that's how you cycle through a multi-dimensional array so we also have some common array functions so let me just show you them so integer that's the entire ease and there's gonna be an array let's say random numbers so 6 comma 8 comma 1 comma then right and now we want to sort this area so all you have to do say echo and sort whatever you want sort so basically int so we got actually echo that out like that so you say sort int you say for for each cycle in re for each and a number let's print out the number so mmm echo the number and that so our original array is 6 8 3 4 2 7 10 and this should get sorted out so that's so yep 2 3 4 6 7 8 10 so that's one of the functions so you can say sort numeric or sort strings then you can also reverse sort this so you can say our sort and this will reverse sorted and now it's 10 8 7 4 6 3 2 so those are some cool stuff you can do with arrays ok so now let's move on to some common string functions that you might use in PHP smooth at remove that ok now let me just create string so STR equals two let's put some white spaces into our string say random string and fight space yeah so as you see this has a lot of white space now what if we wanted to strip down these white spaces so all you have to do is say echo you can say STR lend so the name of the string first of all so you want to trim everything from this side so I'll trim so I'll trim and name of our string okay so now it gives us the length of our string when it's left side has been trimmed now let's also trim the right side our trim okay so that's what it looks like and you can just trim out all the white space about them so for that all you have to say is trim and that will give us and lent out the stream without any white spaces so let's save that and the length of our string without any white spaces is 29 so from this side there were three white spaces this is free white spaces - that's how it's done save that and those are few of the functions that you can use it's trim now there's also the printf function which allows you to print format strings to the screen so let me just show you how to do that - so let's get that back let's remove these so we can say stuff like printf the random string is and you use percentage s out here because we want to print the string and then the line break of course and where we want that person s you just put the name on the string so this is another way to print out strings so the random string is random string with white space so that's how it's done now printf is also cool for conversion codes which are with decimals so let me just show you what I mean so suppose we had a decimal let's say decimal equals to 3 point 1 4 1 and we want to print up to 2 spaces so for that you could say something like let's see number up to two decimal spaces so you say how higher percentage and point 2f because that's the precision that we want now you just print out whatever you want where that person to Jeff is kept so we want to print the decimal so decimal let's see so 3.14 now if we just change this do F it would print out everything and then again if he were just is just point 3f it will print out three decimal spaces yep so that's how it works now other conversion codes include you can use this for binary P is for binary then C is sub characters and D is for integers f is for floating points or doubles as I just showed you o is when integer two octaves S is for Strings and X is four integers 2 hexadecimals now you can also convert strings to uppercase and lowercase so let me just show you that that's purple string STR is let's say that's my name now all you want to do is echo SGR to upload and then just specify the string name so STR I just bring that out so it's all uppercase now if this all uppercase now you see this has the first letter as uppercase so now if you will just say STR to lower so now I'll print everything in lowercase and you can also do you see first so that is only the first thing will be uppercase so you see first so now that's how it's printed so let me just show you there's a really everything don't have a first uppercase so our Paul is a really chill guy now only the first part of the sentence that's not the case so that's how it looks now you can also turn strings into arrays and vice versa so let me show you how to do that so re for Strings you can do the explode method so explode we'll take a delimiter so and the name of the string let's save that now let's just print out for each I say re for string as elements you just want to print out the elements echo elements that's just space them out with commas let's see I think I forgot something somewhere okay you forgot now we have the string called re Paul is a really chill guy and if you go echo you see first only the a part will actually be upper kissed so let me just reload that and I see re Paul is a really chill guy but only yes capital okay so that was all about string functions now let's go ahead and compare strings so first of all let's create two strings STR one equals man and str2 equals now you can compare two strings with compare functions so echo strcmp so STR one so what this will return is actually a positive or a negative number so if man is greater than women in length so let me show you how that works yes minus one so it goes M minus W a - Oh n minus M like that so it returns a positive a string 1 is greater than string 2 and returns a negative a string 1 is less than string 2 so and STR compare is also not case-sensitive okay so that was all about string functions you can check out the rest of the string functions of PHP out here so string functions in PHP and you can very well go through the documentation so these are all there are 94 string functions and you can compare all of them and go through all of them in the documentation now let's just go ahead with functions and end up this video so for functions let's see we have two dumble is num1 equal 7 and ok let's create our function first to create a function that say it's um takes in two numbers number one and - and return num1 plus num2 have to do is say echo some five comma seven and I should actually return you five to seven so yep that's 12 so this wraps up our PHP tutorial video in the further videos I'll show you how to actually connect a MySQL database using PHP and until next time goodbye I hope you have enjoyed listening to this video please be kind enough to like it and you can comment any of your doubts and queries and we will reply them at the earliest do look out for more videos in our playlist and subscribe to any Rekha channel to learn more happy learning
Info
Channel: edureka!
Views: 261,652
Rating: undefined out of 5
Keywords: yt:cc=on, php tutorials, php tutorial for beginners, php programming tutorial, php programming, php programming for beginners, php programming languages, what is php programming, php object oriented programming, php programming with mysql, php functional programming, php programming examples, php programming learning, php programming code, php programming training, php programming download, php tutorial login, install php, php programming knowledge, php training, edureka
Id: hx38tnlYGlA
Channel Id: undefined
Length: 57min 34sec (3454 seconds)
Published: Thu Nov 01 2018
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.