Jump to content

[SOLVED] Adding a string to the end of a varibale name.


Splash

Recommended Posts

Hello everyone.

 

I'm working on a project at the moment and have hit a bit of a brick wall, and am hoping you guys can help me with it.  ;D

 

Basicaly I'm trying to create a new variable by adding a string onto the end of the variable name. i.e.

$Variable1 = 1;
$Variable2."$Variable1" = "Value"

$Variable1++;
$Variable2."$Variable1" = "Value"

Which would result in
$Variable21 = "Value"
$Variable22 = "Value"

 

Does anyone know how this can be achieved?

 

Thankyou  ;D

Splash

Why not just use an array?

<?php
$var = array();

$var[] = 'first value';
$var[] = 'second value';
$var[] = 'third value';

echo $var[0];             // --> 'first value'

echo '<pre>', print_r($var, true), '</pre>';
// -->
// Array
// (
//    [0] => first value
//    [1] => second value
//    [2] => third value
// )


?>

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.