0

I am working in drupal 6, but I think this is more of a php related question than a drupal question.

I am using regex to collect certain values from an the $node object, based on the key I assign the value to a new array to pass this to another function of mine.

Sometimes I get the "Fatal error: Cannot use string offset as an array" error and sometimes I dont...

Here is the code I am using

$dynamic_acc = array();
      foreach($node as $key => $value){            
        //regular expression of the required fields
        $opt_exp = "/^(field_svm_group_and_or_)(\d*)(_qlty)$/";
        $min_exp = "/^(field_svm_group_min_acc_)(\d*)(_qlty)$/";
        $max_exp = "/^(field_svm_group_max_acc_)(\d*)(_qlty)$/";
        if(preg_match($opt_exp, $key)){
          $id_array = preg_split('/_/', $key); //$id_array['5'] will always be an integer
          $dynamic_acc[$id_array['5']]['opt'] = array(
              $key => $value['0']['value'],
              );
        }
        if(preg_match($min_exp, $key)){
          $id_array = preg_split('/_/', $key);
          $dynamic_acc[$id_array['5']]['min'] = array(
              $key => ($value['0']['value'])/(100),
              );
        }
        if(preg_match($max_exp, $key)){
          $id_array = preg_split('/_/', $key);
          $dynamic_acc[$id_array['5']]['max'] =array(
              $key => ($value['0']['value'])/(100),
              );
        }

      }

I have read up about the error on php.net and here on stackoverflow... but I dont really grasp the concept. If anyone could help me out and give me some insight into this issue, it would be greatly appreciated.

1
  • ok... I feel really stupid!! $value[0]['value'] doesn't exist :( I was just programming like a monkey. Commented May 13, 2012 at 8:54

1 Answer 1

1

Most probably $value['0'] is a string and you're trying to treat it as an array.

This error commes up when you do this:

$foo = 'bar';
$foo[0] = 'barbar';
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.