phpeveryday.com

The best tutorial of php, php framework, php strategies, object oriented oriented,


PHP Operators: Assignment Operators

Tag: operator, Assignment Operators   Category: PHP Basic
post: 08 Mar 2008 read: 770


PHP Operators Step By Step Tutorial - Part 3: Assignment operator (=) is operator where the left operand get value from the right operand. It can also be interpreted as giving operator a value to variable. Example:

$x = 100; // which mean x is given by value 100.

The assignment process can also be conducted with the right operand which is in the form of expression.


$y = ($x = 100) + 20;

Assignment operator can also be conducted with the combination of aritmatika operator and string operator which enabling you to use the expression and the result becomes its value.
Example:


$x = 100;
$x += 90;
$x = $x + 90;
$greeting ="good";
$greeting = "night"; // good night

Pay attention that the assignment can copy the original variable into new variable (assignment by value). PHP have supported assignment by reference. Assignment by reference means that some variable which relates in one of same location (is same variable content)

Its syntax:


$var= &$OtherVariable.

Example:
File name: Assignmentoperator.php


<html>
<head>
<title>Using Aritmatika Operator</title>
</head>

<body>
<?
	$x = "red";
	// assignment by reference
	$y = &$x;
	
	// change $x and $y value
	$y = "black";
	
	// remove $x variable from memory
	unset ($x);
	
	// print $y value ="black" 
	print ($y);
?>
</body>
</html>

The result of executing assignment operator.php:

php assignment operators


Series this article:
PHP Operators: Introduction
PHP Operators: Arithmetic Operators
PHP Operators: Assignment Operators
PHP Operators: Assignment Operators Table
PHP Operators: Bitwise Operators
PHP Operators: Relation Operators
PHP Operators: Ternary Operator
PHP Operators: Error Control Operator
PHP Operators: Execution Operator
PHP Operators: Increment or Decrement Operator
php Operators: Logic Operator
PHP Operators: String Operator
PHP Operators: Array Operator
PHP Operators: Object Operator
PHP Operators: Operator Priority
PHP Constants: Introduction

| Give Your Opinion | Recommend
Share and Bookmark to: These icons link to social bookmarking sites where readers can share and discover new web pages.
digg del.icio.us technorati Ma.gnolia BlinkList

Recommended articles by other readers:
Web Services: How PHP Kiss VB.NET? (Part 1)
Joomla: Fast Road to Understand Component Programming
Chart: How to Build Cool Animation Real Time Chart
Email: Send Attachement Mail
SMS : Sending SMS with PHP and ActiveXperts (Part 1)

What do You Think?
Your Name *:
Email *:
(Will not be published)
Website/URL:
Your Comment *:
* Required


624
posting