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
https://forums.phpfreaks.com/topic/210556-echoing-defined-variables-from-an-array/
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'];

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.