Jump to content

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.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.