string offset as an array

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.

Answers


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';

Need Your Help

ExternalException saving System.Drawing.Bitmap with same name in different folder

vb.net debugging exception bitmap

I'm working on an automated image cropper, and whenever I save the cropped image as an arbitrary name (example: C:\test.jpg -> C:\blargh.jpg) it works fine, but when I save it with the same filenam...

What are the pros and cons of LinkedHashMaps vs. LinkedHashSets?

java linkedhashmap linkedhashset

Could someone explain the main benefits for choosing one over the other and the detriments that come with that choice?