1

I want to do a concatenation to call my define but php don't want.

By example :

define('FOO_1', 'string 1');
define('FOO_2', 'string 2');

I want to call it dynamically :

$id = 1;
echo FOO_.$id;

But it displays :

FOO_1
(not "string 1");

How can I call my define dynamically ?

0

1 Answer 1

6

By using constant()

echo constant('FOO_'.$id);

See doc here: http://php.net/constant

credits to Yent

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.