2015-07-02 55 views
-2

我有一個來自聯接查詢時,我調試發現此輸出的數組。 這是我在控制器Cake php多維數組

$agetFeatureGigs = $this->Gigs->getFeatureGigs(); 
$this->set('agetFeatureGigs', $agetFeatureGigs); 

$yourValue='7'; 
foreach($agetFeatureGigs as $key => $val) { 
    $agetFeatureGigs[$key]['Gigs']['manual'] = $yourValue; 
} 

輸出

array(
    (int) 0 => array(
     'usersjoin' => array(
      'action' => 'YES' 
     ), 
     'Gigs' => array(
      'id' => '2', 
      'username' => 'nmodi', 
      'category' => 'Creativity & Designing', 
      'subcategory' => 'Logo Design', 
      'picture' => 'Banner_logo1.jpg', 
      'video' => '', 
      'title' => 'I will design 2 AWESOME logo design in 48 hours', 
      'delivery' => '24 Hrs', 
      'workinghrs' => '3', 
      'feature' => 'YES', 
      'action' => 'YES', 
      'del' => 'NO' 
     ) 
    ), 
    (int) 1 => array(
     'usersjoin' => array(
      'action' => 'YES' 
     ), 
     'Gigs' => array(
      'id' => '1', 
      'username' => 'ptailor', 
      'category' => 'Creativity & Designing', 
      'subcategory' => 'Logo Design', 
      'picture' => '128.jpg', 
      'video' => 'https://www.youtube.com/watch?v=KtCF5tyAr-o&feature=inp-gs-IOL-07-47', 
      'title' => 'I will proofread and edit your document I will proofread and edit your document', 
      'delivery' => '12 Hrs', 
      'workinghrs' => '2', 
      'feature' => 'YES', 
      'action' => 'YES', 
      'del' => 'NO' 
     ) 
    ) 
) 

代碼,但我需要添加一個字段評級手動值婁德爾內裏演出陣列。 請幫我解決這個問題。

回答

0

如果你需要插入相同的值到您的數據中每個Gigs陣列可以使用CakePHP's Hash utility這樣的: -

Hash::($data, '{n}.Gigs.rating', $value); 

哪裏$data是您的陣列和$value是你想用插入值rating的關聯密鑰。

Hash將工作兩個CakePHP的2和3只記得蛋糕3,你需要處理這樣的命名空間上面是可以做到: -

Cake\Utility\Hash::($data, '{n}.Gigs.rating', $value); 

如果你需要插入不同的值,那麼你將需要在陣列上循環: -

foreach ($data as &$item) { 
    $item['Gigs']['rating'] = $value; 
} 
+0

什麼也沒有發生同樣的調試值 – ggutigod

+0

你試過了哪種方法? – drmonkeyninja

+0

來調試? <?php debug($ agetFeatureGigs);?> – ggutigod