Jump to content

Echoing defined variables from an array.


Rohlan

Recommended Posts

Hello.

 

I have an array like this:

 

Array
(
    [1] => MOR
    [2] => CON
    [3] => CP1
    [4] => CP2
    [5] => EMAIL
    [6] => NIF
    [7] => BI
    [8] => DIS
)

 

And then I defined, for example this one variable:

 

define("DIS","District");

 

When I try to...

 

	
echo $array[8];

 

All I get is "DIS".

 

I'm obviously trying to echo a string and it won't work that way... but I still gave it a try. How can I do this then? I need "District" to be outputted instead of the actual variable name.

 

I know that if I were to "echo DIS;" this would work but that defeats the purpose as I have various defined variables per row...

 

Thanks.

 

 

Link to comment
Share on other sites

I edited my post as I was making little sense in some bits.

 

But I will try your tip! thanks..

 

Edited: It works!

Thanks! i didnt know that function... i guess i shouldve searched a bit better.. hehe...

 

Cool.  I'm curious why you wouldn't use an array like this:

 

$array['DIS'] = 'District';
//etc

echo $array['DIS'];

Link to comment
Share on other sites

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.