> Online tutorial : php
Showing posts with label php. Show all posts
Showing posts with label php. Show all posts

Assignment Operators in php


Assignment Operators
Assignment operators are used to set a variable equal to a value or set a variable to another variable's
value. Such an assignment of value is done with the "=", or equal character.

Example: 

•  $my_var = 4; 
•  $another_var = $my_var  

Now both $my_var and $another_var contain the value 4. Assignments can also be used in conjunction
with arithmetic operators.
  

Arithmetic Operators in php

Using Arithmetic Operators
To perform mathematical operations on variables, use the standard arithmetic
operators, as illustrated in the following example:

<?php

// define variables

$num1 = 101;

$num2 = 5;

// add

$sum = $num1 + $num2;

// subtract

$diff = $num1 - $num2;

// multiply

$product = $num1 * $num2;
// divide

$quotient = $num1 / $num2;

// modulus

$remainder = $num1 % $num2;

?>



To perform an arithmetic operation simultaneously with an assignment, use the

two operators together. The following two code snippets are equivalent:


<?php

$a = $a + 10;

?>

<?php

$a += 10;

?>


Operator What It Does
= Assignment
+ Addition
- Subtraction
* Multiplication
/ Division; returns quotient
% Division; returns modulus
&& Logical AND
|| Logical OR
xor Logical XOR
! Logical NOT
++ Addition by 1

Data types in PHP


Understanding Simple Data Types


Every language has different types of variables—and PHP has no shortage of choices.
The language supports a wide variety of data types, including simple numeric,
character, string, and Boolean types, and more complex arrays and objects.

Data Type Description Example
Integer An integer is a plain-vanilla

number like 75, -95, 2000,

or 1.
$age = 99;
Boolean The simplest variable type

in PHP, a Boolean variable

simply specifies a true or

false value
$auth = true;
Floating-point A floating-point number

is typically a fractional

number such as 12.5

or 3.149391239129.

Floating point numbers may

be specified using either

decimal or scientific notation.
$temperature = 56.89;
String A string is a sequence of

characters, like 'hello' or

'abracadabra'. String

values may be enclosed in

either double quotes ("") or

single quotes ('').
$name = 'Harry';
In many languages, it’s essential to specify the variable type before using it; for

example, a variable may need to be specified as type integer or type array.

Give PHP credit for a little intelligence, though—the language can automagically

determine variable type by the context in which it is being used.

Writing Statements and Comments in php


Writing Statements and Comments


As you can see from the previous example, a PHP script consists of one or more
statements, with each statement ending in a semicolon. Blank lines within the
script are ignored by the parser. Everything outside the tags is also ignored by the
parser, and returned as is; only the code between the tags is read and executed.

TIPS

If you’re in a hurry, you can omit the semicolon on the last line of a PHP
block, because the closing ?> includes an implicit semicolon. Therefore,
the line is<?php echo 'Hello' ?>  perfectly valid PHP code.
This is the only time a PHP statement not ending in a semicolon is still
considered valid.
For greater readability, you should add comments to your PHP code, as I did in
the previous example. To do this, simply use one of the Comments styles listed here:


<?php


// this is a single-line comment

# so is this

/* and this is a

multiline

comment */

?>

Feature in PHP

Features

As a programming language for the Web, PHP is hard to ignore. Clean syntax,
object-oriented fundamentals, an extensible architecture that encourages innovation,
support for both current and upcoming technologies and protocols, and excellent
database integration are just some of the reasons for the popularity it currently
enjoys in the developer community.

Simplicity:

                 Because PHP uses a consistent and logical syntax, and because it comes with
a clearly written manual, even novices find it easy to learn. In fact, the quickest
way to learn PHP is to step through the manual’s introductory tutorial, and then
start looking at code samples off the Web. Within a few hours, you’ll have learned
the basics and will be confident enough to begin writing your own scripts. This
adherence to the KISS (Keep It Simple, Stupid) principle has made PHP popular
as a prototyping and rapid application development tool for web applications. PHP
can even access C libraries and take advantage of program code written for this
language, and the language is renowned for the tremendous flexibility it allows
programmers in accomplishing specific tasks.

Portability:

With programming languages, portability—the ease with which a program can
be made to work on different platforms—is an important factor. PHP users have
little to fear here, because cross-platform development has been an important
design goal of PHP since PHP 3.0. Today, PHP is available for a wide variety of
platforms, including UNIX, Microsoft Windows, Mac OS, and OS/2. Additionally,
because PHP code is interpreted and not compiled, PHP scripts written on one
platform usually work as is on any other platform for which an interpreter exists.
This means that developers can code on Windows and deploy on UNIX without
any major difficulties.

Speed:

          Out of the box, PHP scripts run faster than most other scripting languages, with
numerous independent benchmarks putting the language ahead of competing
alternatives like JSP, ASP.NET, and Perl. When PHP 4.0 was first released, it
raised the performance bar with its completely new parsing engine. PHP 5.0
improves performance even further through the use of an optimized memory
manager, and the use of object handles that reduce memory consumption and
help applications run faster.


Open Source:

         Possibly the best thing about PHP is that it’s free—its source code is freely
available on the Web, and developers can install and use it without paying licensing
fees or investing in expensive hardware or software. Using PHP can thus significantly
reduce the development costs of a software application, without compromising on
either reliability or performance. The open-source approach also ensures faster bug
fixes and quicker integration of new technologies into the core language, simply
due to the much larger base of involved developers.

Extensible:

Keeping future growth in mind, PHP’s creators built an extensible architecture
that enables developers to easily add support for new technologies to the language
through modular extensions. This extensibility keeps PHP fresh and always at
the cutting edge of new technology. To illustrate this, consider what PHP lets you
do through its add-on modules: dynamically create image, PDF, and SWF files;
connect to IMAP and POP3 servers; interface with MySQL, Oracle, PostgreSQL

,and SQLite databases; handle electronic payments; parse XML documents; and
execute Perl, Java, and COM code through a PHP script. And as if all that wasn’t
enough, there’s also an online repository of free PHP classes called PEAR, the
PHP Extension and Application Repository, which provides a source of reusable,
bug-free PHP components.


BUY IT: