0

I would try to setting an element of an array with the following code:

if (empty($table['keys'])){
    $table['keys']=array(
        'primary_key'=>array(
            'id'
        )
    );
}

But I get the 'illegal string offset...' warning. I also tried another array key, in case of the 'keys' index would be reserved keyword, but it makes the same error.

1
  • Does not give me any error at all... see eval.in/511929 Commented Feb 2, 2016 at 14:27

2 Answers 2

1

The variable $table appears to be a string. try this before your if-statement:

if(!is_array($table)) $table = [];

or if the change will only take place if $ tablet is an array

if(is_array($table)) {
  if(!array_key_exists('keys', $table)||empty($table['keys'])) {
    $table['keys']=array(
        'primary_key'=>array(
            'id'
        )
    );
  }
}
Sign up to request clarification or add additional context in comments.

1 Comment

Yeah, the variable at some modules is string, not an array. This caused the problem. Thanks for your help! :)
0

Try it like this

if( empty($table['keys']) ){
 $table['keys'] = [
   'primary_key' => [
      'id' => ""
    ]
 ];
}

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.