Learn PHP : Hour 2





If you have missed PHP Hour 1 then Click Here Learn PHP : Hour 1

Lets start to learn more about basics of PHP.

Variables in PHP

Variables are used for storing a value, like text strings, numbers or arrays.

When a variable is set it can be used over and over again in your script

All variables in PHP start with a $ sign symbol.

The correct way of setting a variable in PHP:
$var_name = value;

New PHP programmers often forget the $ sign at the beginning of the variable. In that case it will not work.

Let's try creating a variable with a string, and a variable with a number:

<?php

$txt = "Hello World!";

$number = 16;
?>


Strings in PHP

String variables are used for values that contains character strings.

For Example: the PHP script assigns the string "Hello World" to a string variable called $txt:

<?php
$txt="Hello World";
echo $txt;
?>

The output of the code above will be:

Hello World

Using the strlen() function
The strlen() function is used to find the length of a string.
Let's find the length of our string "Hello world!":

<?php
echo strlen("Hello world!");
?>

The output of the code above will be:
12

***END Hour 2***
If you have missed PHP Hour 1 then Click Here Learn PHP : Hour 1




1 comment:

  1. Get all Technology Updates Learn latest technology, software development skills, b.tech, MCA and BCA computer

    programming training.

    ReplyDelete

We are here to listen you, Comment your valueable opinion...!!!