0

I want to define constants like this

    $a = 0;
    foreach ($data as $key) {
        define('SN', array($key->SN));
        define("CODE".$a, $key->Code); 
        $a++;
    }   

It works in php 7.0 but how to define it like this in php 5.4 ?

1
  • I font think that works in 7 either since you cant redefine SN Commented Oct 5, 2018 at 6:41

1 Answer 1

2

According to the docs at http://php.net/manual/en/function.define.php its not possile to use constants with array values.

The value of the constant. In PHP 5, value must be a scalar value (integer, float, string, boolean, or NULL). In PHP 7, array values are also accepted.

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

3 Comments

I think he wants a solution, How can he achieve it in some other way?, Perhaps work on "scope" ?
There is no solution, other than to scrape the idea of constant usage.
Somebody said to me "nothing is impossible to achieve in programming" ... I guess he was wrong then

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.