0

I'm struggling with my array. I get a array like this:

Array
(
    [state] => Array
            (
                [0] => Array
                    (
                        [state] => 1
                    )

                [1] => Array
                    (
                        [state] => 2
                    )

            )
)

I want to change the 1 to 'active' and the 2 to 'inactive'. I've allready a controller which get this 1 and 2. Controller look likes:

if ($name == 'state') {
    foreach ($dropdownArray[$name] as $arrayName) {
        if ($arrayName[$name] == '1') {
            echo $arrayName[$name];
            $arrayName[$name] = 'active';
        } else {
            echo $arrayName[$name];
            $arrayName[$name] = 'inactive';
        }
    }
 }

With $name I get the value from the dropdown field. So in this case $name = state.

As expected, I get the 1 and 2 in an echo. So he get the good values. But how to set this values to Active and Inactive?

1 Answer 1

1

Use $dropdownArray[$name] instead of $arrayName[$name] like that

foreach ($dropdownArray[$name] as $key=>$arrayName) {
    if ($arrayName[$name] == '1') {
        $dropdownArray[$name][$key][$name] = 'active';
    } else {
        $dropdownArray[$name][$key][$name] = 'inactive';
    }
}
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.