Category: php

.

Variable Variables in PHP

i-1

Every so often when you are writing a php file, we all run into a situation where we would like for the name of the

string that is inside of your php variable to be converted into the actual name of another variable.

After a fair amount of hunting around the internet and getting sent off into PHP code hunting limbo for a few hours, I suddenly remembered that this was something that I had  found a solution to some time ago. Now, had I been prudent about my little discovery, I would have put it up here on mrarrowhead.com. Instead I forgot about it until I accidentally ran across variable variables agains in the php manual. Variable variables was exactly what I was looking for to get a string from one variable and change it to the name of another variable in my php scipt.

So here goes:

 

<php

$var = varIwannaMake;

$$var = Im in varIwannaMake;

echo $$var. //<--- this will output the above sentence;

echo $varIwannaMake; // this will output the same thing

 

?>

 

The scirpt above will output the following:

Im in varIwannaMake

Im in varIwannaMake

 

Short and sweet  - simple to use -- hope you like.

 

 

 

Author: D.Shaun Morgan

how to open create write files php Php file functions, Opening a file in php, reading a file in php, writing a file in php In this tutorial we will look at the most commonly used file functions used in php. The

how to write php functions php Explanation of a Basic PHP Function What is a PHP function? In PHP a function represents a block of instructions that perform

how to write html form PHP php When learning PHP to build a website, one of the very first things that any newcomer, or beginner needs to learn is how to use HTML or XHTML (both will mean the same for this tutorial.) fo

how to install php 5 php This is a quick start beginner's how-to manual explaining how to quickly setup a PHP 5 installation on a Windows XP PC. You must have an Apache webserver installed and working on your personal comp

php passing variables php Pass Variables from One Page to Another -- PHP Author: D.Shaun Morgan Tutorial Outline : Passing PHP variables with $_

.
 

Leave a Comment

how-to-turn-variable-value-into-variable-name

Name:      | Email:      | Website:

Comment:


captcha

Enter The Above Security Code: