I want PHP to determine if a number is included in the value of a particular array.

Asked 2 years ago, Updated 2 years ago, 483 views

I'm a beginner in PHP.

One variable: TestPosition
If the number in the array of A is A
Similarly, if included in the array of B, B
I would like to create a function that returns .

I tested if I could use in_array as shown below, but I got an error.

error messages:

Use of undefined constant A_CERTAIN_AREA_ARRAY-assumed 'A_CERTAIN_AREA_ARRAY' (this will throw an Error in a future version of PHP)

I don't understand why they call me undefined constant even though I'm declaring it

Also, will constants be treated as errors in future php versions?

class TEST {
    const A_CERTAIN_AREA_ARRAY = [1,11,13];
    const A_CERTAIN_AREA_B_ARRAY = [2,22,23];
    const A_CERTAIN_AREA_C_ARRAY = [3,23,53];

    public function index (Request$request)
    {
        $testPosition=3;
        Log::debug(":."."test", in_array($testPosition, A_CERTAIN_AREA_ARRAY, true));
        return view ('index');
    }
}

php laravel

2022-09-30 21:56

1 Answers

A constant name is not enough to reference a class constant.
self::A_CERTAIN_AREA_ARRAY to identify the class.


2022-09-30 21:56

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.