I'm new to php and arrays. I have an array named $get which contains:
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)
I am looping each one of them to decrypt it. How can I save it to an array or overwrite the array itself with the decrypted one? Here's how I decrypt and loop it.
$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']);
}
I've searched also but seems they have different implementation. Thanks!
You can do it like this:
$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']);
}
like this you can do it dynamically
$decrypted = [];
foreach ($get as $key => $result) {
foreach ($result as $input => $value) {
$decrypted[$key][$input]= $decr->decrypt($value);
}
}