Skip to main content

Posts

Showing posts with the label Php Programming

Single quotes vs Double quotes:-

  So you can use single or double quotes for Strings. But what’s the difference? Let’s take a look. The main difference between single and double quotes is any string in double-quotes will be processed by PHP before it’s outputted. That means, for example, any variables in strings with double quotes will become their literal value. Let’s take a look at an example here. Where on the left side of the screen, I have my code and on the right side of the screen, I have the It in the browser. I’ll type my opening PHP tag. And then I will create a variable called name. So we’ll say, the name gets Joe and I’ll put Joe in single quotes. Then we’ll say Echo? Double quote. Hello, comma space name. Remember PHP Prince exactly as we type within the quotes so we need to add any punctuation spaces and things. Like that. Then we’ll add our semicolon will save this and will refresh the page. You can see it says, hello Joe. Now, if we change this string to single quotes, first of all, you’ll notice that

Using variables:-

  Printing   information onto the screen is great, but we don’t always know exactly what information we want to print. While we’re writing our code. For example, if we want to print the visitor’s name, there’s no possible way of knowing that information before they visit. That’s where variables come in variables, are a way to store information in order to reference it later variables can be used to store numbers names or other important data in HP variables must start with a dollar sign followed by a letter or an underscore then an alphanumeric character string. Here’s an example. You see that we have our opening PHP tags, a dollar sign followed by the wordage, and then an equal sign and some value. In this case, 34, and we have our semicolon. Age is a placeholder for the number that we have stored in it. Which is 34 PHP knows age is 34 because of the equal sign, which means is assigned to or gets, I’ll usually say, gets when referencing variables, we can then use age as if it’s the nu

What is Array in PHP?

  Now that, you know what arrays are? Let’s look at how to use them in PHP, starting with indexable arrays. All right. My opening PHP tags. On a comment here, indexable array. And let’s create that color array. So the array is going to have a name just like any other variable with a dollar sign first. So we’ll say colors, get, and then we’re going to use the keyword array and inside of the parenthesis for the array function or keyword, we’re going to have a comma-separated list of items. We’ll say, red, blue, and green. So if we want to see what this array looks like, we can use a special function called print r. That will print the array nicely for us. So we’ll say print our colors. I’ll save this, and then I’ll go to the browser. And you can see that the array is a simple array with our indexes as numbers, starting at 0. That means that if we want to reference a specific color, we would do so by writing Echo, colors, square bracket, and then the index. So if we wanted to print blue w

What are arrays, and how do they work?

  Arrays are a bit different from the rest of our variables arrays act, as key-value pairs, that essentially function as a set of variables. So this allows us to make a list of related items that we can reference. As one big variable, the benefit of organizing data this way is it’s easier to manage when we’re working with related values or complex data sets, like when retrieving information from a database array values can be Any of the data types that standard variables can be, and we can mix them, so we can have an array that includes strings only an array that includes integers only or an array that includes integers strings characters or anything else you can think of there are two types of arrays. You should know about indexable or is which use numbered keys and associative arrays which use strings is Keys, you’ll learn how to define each of those PHP later. But for now, let’s learn a little bit about how they work. As a concept indexable, arrays are basically numbered lists each