Skip to main content

String Variable in PHP

$coats1 = "Winter Coats";

Again, our variable name starts with a dollar sign ($).

We've then given it the name coats1. The equals sign follows the variable name. After the equals sign, however, we have direct text - Winter Coats. Then you can also put text into your variables.

Assume you want to know something about the coats you own. Are they Winter coats? Jackets? Summer coats? You decide to catalogue this, as well. You can put direct text into your variables. You do it in a similar way to storing numbers:

j2program


But notice the double quotation marks around our text. If you don't surround your direct text with quotation marks, then you'll get errors. You can, however, use single quotes instead of double quotes. So you can do this:

$coats1 = 'Winter Coats';

But you can't do this:

$coats1 = 'Winter Coats";

In the above line, we've started with a single quote and ended with a double quote. This will get you an error.

We can store other text in the same way:
Samurdhika
ICT Lecture Samurdhika

$coats2 = "Jackets";

$coats3 = "Summer Coats";

The direct text will then get stored in the variable to the left of the equals sign.

So, to recap, variables are storage areas. You use these storage areas to manipulate things like text and numbers.

You'll be using variables a lot, and on the next few pages you'll see how they work in practice.

Comments

Popular posts from this blog

Nodejs Events

Events in Node.js The EventEmitter Object You can assign event handlers to your own events with the EventEmitter object. In the example below we have created a function that will be executed when a "scream" event is fired. To fire an event, use the  emit()  method. var events = require('events'); var eventEmitter = new events.EventEmitter();  //Create an event handler:  var myEventHandler = function () {   console.log('I hear a scream!');  }  //Assign the event handler to an event: eventEmitter.on('scream', myEventHandler);  //Fire the 'scream' event:  eventEmitter.emit('scream');

Family get-together with Ramadan Ifthar 2017

Family get-together with Ramadan Ifthar 2017

Node.js and Raspberry Pi

Raspberry Pi is a small, multi-use computer. With Node.js you can do amazing things with your Raspberry Pi. What is the Raspberry Pi? The Raspberry Pi is a small, affordable, and amazingly capable, credit card size computer. It is developed by the Raspberry Pi Foundation, and it might be the most versatile tech ever created. Creator Eben Upton's goal was to create a low-cost device that would improve programming skills and hardware understanding. Due to the small size and price of the device, it has become the center of a wide range of projects by tinkerers, makers, and electronics enthusiasts. Raspberry Pi and Node.js The Raspberry Pi has a row of GPIO (General Purpose input/output) pins, and these can be used to interact in amazing ways with the real world. This tutorial will focus on how to use these with Node.js. Write Raspbian OS Image to MicroSD Card Before we can start using our Raspberry Pi for anything, we need to get a OS installed. ...