Reputation: 828
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.
Upvotes: 0
Views: 456
Reputation: 3162
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';
Upvotes: 1