phpeveryday.com

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


PHP Basic: Variable Variable

Tag: data type, variable   Category: PHP Basic
post: 01 Mar 2008 read: 191


PHP Basic Data Type Step By Step Tutorial - Part 13: Variable variable is variable which takes a value from one variable and treating it as a name of variable. Thereby, a variable can be determined and used dynamicly.

Example :


$a=25;
$$a=225;

It means a filled by 25 and 25 filled by 225


$goods="pen";
$$goods=1500;

It means goods filled with "pen" and " pen" filled by 1500.

Pay attention to the example of using variable with static at script as following:
File name:variablevariable.php


<html>
<head>
<title>Variable variable</title>
</head>

<body>
	<h1>Using Variable variable</h1>
	<pre>
		$code = "titus"
		${$code} = "smart"
		<h1>Print :</h1>
		$code = $code
		${$code} = ${$code}
		$titus = $titus
	</pre>
	<h1>Hasil :</h1>
<?	
	$code = "titus";
	${$code} = "smart";
	print "\$code = $code"."<br>";
	print "\${$code}= ${$code}"."<br>";
	echo "\$titus = $titus"."<br>";
?>
</body>
</html>
php basic variable variable



| 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