2012-05-13 44 views
0

我在drupal 6中工作,但我認爲這是一個比drupal問題更多的php相關問題。作爲數組的字符串偏移量

我正在使用正則表達式來從$ node對象收集某些值,根據該鍵將值賦給一個新數組,以將此值傳遞給我的另一個函數。

有時我得到的「致命錯誤:無法使用字符串數組offset」的錯誤,有時我不...

這裏是我使用

$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), 
      ); 
     } 

     } 

代碼我已經閱讀了關於php.net和這裏在stackoverflow上的錯誤...但我真的不明白這個概念。如果有人能幫助我,並讓我對這個問題有所瞭解,將不勝感激。

+0

確定...我覺得自己很愚蠢! $ value [0] ['value']不存在:(我只是像猴子一樣編程。 – Beyerz

回答

1

大多數可能$ value ['0']是一個字符串,你試圖把它當作一個數組。

,當你這樣做此錯誤commes起來:

$foo = 'bar'; 
$foo[0] = 'barbar'; 
相關問題