TalkPHP
 
 
Account Login
Latest Articles
» The basic usage of PHPTAL, a XML/XHTML template library for PHP
» Vulnerable methods and the areas they are commonly trusted in.
» Simple way to protect a form from bot
» The Basics On: How Session Stealing Works
» How to keep your forms from double posting data
IRC Channel
IRC Speech Bubble Join the friendly bunch on IRC...
(#TalkPHP on Freenode)

...Also available via a web interface.

See this thread for information on the TalkPHP Free Hugs Initiative™. Subject to availability.
Associates
Associates
CSS Tutorials
Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old 04-27-2008, 06:29 PM   #1 (permalink)
The Addict
 
sarmenhb's Avatar
 
Join Date: Jan 2008
Location: los angeles
Posts: 309
Thanks: 44
sarmenhb is on a distinguished road
Default when would i use a "variable variable"

by a variable variable(dynamic Variable) i mean

Code:
<?php

$field = "firstname_field";
$$field = "sarmenhb";

echo "Field Name: ".$field."<br>";
echo "Field Value: ".$$field."<br>";
?>
have you ever used this in your code? if so can you explain how you used it?

thanks
__________________
no signature set
sarmenhb is offline  
Reply With Quote
Old 04-27-2008, 07:43 PM   #2 (permalink)
The Acquainted
 
freenity's Avatar
 
Join Date: Feb 2008
Posts: 119
Thanks: 17
freenity is on a distinguished road
Default

check this, should help you to understant:

PHP Code:
<?php
$a 
'b';

$b 2;
$
$a 55;

var_dump($b);
The output is: 55
__________________
http://feudal-times.net - My PBB Game
http://gwphp.feudal-times.net - My Blog "Gaming With PHP"
freenity is offline  
Reply With Quote
Old 04-27-2008, 08:05 PM   #3 (permalink)
The Addict
 
Join Date: Nov 2007
Posts: 264
Thanks: 2
TlcAndres is on a distinguished road
Default

It's also something of a bit of help when your doing basic skinning for example

PHP Code:

function load($file,$array){
  foreach(
$array as $key => $val){
    ${
$key} = $val;
  }
  require_once(
$file);

with that you do something like this

PHP Code:
$skinCons = array('title'=>'Production Site','content'=>'test content of stuff');
load('skin.php',$skinCons); 
the skin file would look like
PHP Code:
<html>
<head>
<title><?php echo($title);?></title>
</head>
<body>
<?php echo($body); ?>
</body>
</html>
__________________
"What everyone seems to forget is that while knowledge certainly is something - it's the implementation of knowledge that brings power" - Andres Galindo.
TlcAndres is offline  
Reply With Quote
Old 04-28-2008, 03:42 PM   #4 (permalink)
The Wanderer
 
blayne4k's Avatar
 
Join Date: Apr 2008
Location: Trapped in my own little world.
Posts: 14
Thanks: 0
blayne4k is on a distinguished road
Default

Almost all of the variable variables ive seen were inside of loops or loops inside of loops, things like that need to be able to generate dynamic variables and still know what they are, although most of the time I just use arrays, they work just as good and its easier to output them just with a print_r
blayne4k is offline  
Reply With Quote
Reply



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


All times are GMT. The time now is 07:02 AM.

 
     

Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0
Inactive Reminders By Icora Web Design