2014-10-17 232 views
0

我是新來的PHP和數組。我有一個名爲$ get的數組,其中包含:陣列推到多維陣列

array (size=5) 
0   => 
array (size =3) 
'name' => string '6Jj3sHDG2Dciq92P0fELyw==' (length     =24) 
'email' => string 'uYyYxVif7yOSO+nxLXRoKxj8oulFOp9EONDvMXC+zE8=' (length=44) 
'password'=> string 'umxCWS0OXGTomcDWkHZUCA==' (length     =24) 

1   => 
array (size =3) 
'name' => string 'GjtDUw6NwmjQuoG/lwWYcg==' (length     =24) 
'email' => string 'gHi5V7tzYABdlb1iCr8Tuw==' (length     =24) 
'password'=> string 'umxCWS0OXGTomcDWkHZUCA==' (length     =24) 

2   => 
array (size =3) 
'name' => string 'PB/6qLhQ/xe8iRmjWglb8g==' (length     =24) 
'email' => string 'ZvTXUau05ubgzOEn/cY0XQ==' (length     =24) 
'password'=> string 'umxCWS0OXGTomcDWkHZUCA==' (length     =24) 

3   => 
array (size =3) 
'name' => string 'nYFzzMaZxZ7F5zV9jE7X5A==' (length     =24) 
'email' => string '0oyJhuD9u5PHLku+wV9xhQ==' (length     =24) 
'password'=> string 'umxCWS0OXGTomcDWkHZUCA==' (length     =24) 

4   => 
array (size =3) 
'name' => string 'XEJyjRWo0jKt4XjSRct6/A==' (length     =24) 
'email' => string 'JQyW/v9RATiJs8m9QwPRwA==' (length     =24) 
'password'=> string 'umxCWS0OXGTomcDWkHZUCA==' (length     =24) 

我正在循環其中的每一個來解密它。我怎樣才能將它保存到一個數組或用解密的數組覆蓋數組?這是我解密和循環的方式。

$get = Users::getAll(); 
    $decr= new Cipher("somekey"); 
    foreach($get as $result) 
    { 
     //Decryption 
     $new_decrypted_name = $decr->decrypt($result['name']); 
     $new_decrypted_email = $decr->decrypt($result['email']); 
     $new_decrypted_password= $decr->decrypt($result['password']); 
    } 

我也搜索過,但似乎他們有不同的實施。謝謝!

回答

1

你可以這樣說:

$get = Users::getAll(); 
    $decr = new Cipher("somekey"); 
    foreach($get as $key => $result) 
    {  
     $get[$key]['name'] = $decr->decrypt($result['name']); 
     $get[$key]['email'] = $decr->decrypt($result['email']); 
     $get[$key]['password'] = $decr->decrypt($result['password']); 
    } 
+0

謝謝!正是我想要的。完善。 – jackhammer013 2014-10-17 06:03:52

0

這樣你可以做動態

$decrypted = []; 
foreach ($get as $key => $result) { 
    foreach ($result as $input => $value) { 
    $decrypted[$key][$input]= $decr->decrypt($value); 
    } 
}