Fatal error: Uncaught Error: [] Operator not supported for strings in

Asked

Viewed 61 times

0

Hello.

I have a options with custom fields in a form.

I’m getting the Fatal error: Uncaught Error: [] operator not supported for strings

I have read that [] is an operator no longer allowed after php 7.0

the code is as follows:

$results = $this->getCustomFieldsByLocation($location, $customer_group);

        $custom_fields = array();
        foreach($results as $key => $custom_field){

            $custom_fields['custom_field.'.$location.'.'.$custom_field['custom_field_id']] = array(
                'id' => 'custom_field.'.$location.'.'.$custom_field['custom_field_id'],
                'title' => $custom_field['name'],
                'tooltip' => '',
                'error' => '',
                'type' => $custom_field['type'],
                'options' => '',
                'refresh' => '0',
                'custom' => 1,
                'location' => $custom_field['location'],
                'sort_order' => $custom_field['sort_order'],
                'value' => $custom_field['value'],
                'class' => '',
                // 'display' => 1,
                // 'require' => $custom_field['required'],

            );

            if(!empty($custom_field['custom_field_value'])){

                foreach($custom_field['custom_field_value'] as $option){

                    $custom_fields['custom_field.'.$location.'.'.$custom_field['custom_field_id']]['options'] [] <-- aqui esta o erro --> = array(
                        'name' =>  $option['name'],
                        'value' =>  $option['custom_field_value_id'],
                    );
                }
            }
        }

        return $custom_fields;
    }

I tried to recreate the array, but I get other errors.

And by removing [] I get no value within options.

Could someone help?

Thank you

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.