Jump to content

php variables combined


dodgeitorelse

Recommended Posts

Hi everyone,

I have several variables named $list1 through $list20.

I need to know if it is possible to use another variable to fill in the number at the end of the first variable depending on a server that is selected.

The variable to determine the server is $server['o']['id']

The id is a number from 1 - 20

I tried $list{$server['o']['id']} but all I get for a value is the number and not the $list before it.

Due to the existing code that I am trying to use this in I have to be able to do this inside single quotes as double quotes kills all the code (shows nothing but a blank page for everything)

How can this be achieved?

Link to comment
https://forums.phpfreaks.com/topic/241062-php-variables-combined/
Share on other sites

To dynamically generate variable names, the curly quotes need to go around the entire variable name:

 

${'list' . $server['o']['id']}

 

Thank you very much . I had tried the curly quotes but put first one before the dollar sing instead of after. Again thank you for your working solution.  :D

I've heard curly braces called curly bracketsflower brackets - squiggly brackets - curvy brackets - curvy braces , and yes even more.

The first 3 are commonly used depending what country you live in.

 

But in no way is { or } a quote.

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.