phpeveryday.com

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


What the meaning of &$var?

Tag: variable   Category: PHP Basic
post: 30 Oct 2007 read: 516


May be you find &$variable in somebody's code. Don't confuse with this "stranger" variable. It means assigning a variable by reference.

Please look this example:


<?php

// An example of assigning variables by value
$yours = "this value from yours <br/>";
$mine = $yours;
echo "my var: ".$mine;
// output: my var: this value from yours 

$mine = "this value from mine <br/>";
echo "your var: ".$yours;
// output: your var: this value from yours 

//An example of assigning variables by reference
$mine = &$yours;

$yours = "this value from yours <br/>";
echo "my var: ".$mine; 
// output: my var: this value from yours

$mine = "this value from mine <br/>";
echo "your var: ".$yours;
// output: your var: this value from mine

?>



| 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)
Chart: How to Build Cool Animation Real Time Chart
Joomla: Fast Road to Understand Component Programming
Email: Send Attachement Mail
mod_rewrite - Part 1: create your "fantasy" URL

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


615
posting