3v4l.org

run code in 200+ php & hhvm versions
Bugs & Features
<?php $controlValue = [ 'item1' => 'val1', 'item2' => 'val2', 'item3' => [ 'item4' => 'val4', 'item5' => 'val5', ], ]; $encryptedFields = [ 'item2', 'item3.item5', ]; foreach ($encryptedFields as $encryptedField) { if (strpos($encryptedField, '.') !== false) { $encryptedFieldSegments = explode('.', $encryptedField); $encryptedFieldSegment = array_shift($encryptedFieldSegments); if (!isset($controlValue[$encryptedFieldSegment])) { continue; } $valueReference = &$controlValue[$encryptedFieldSegment]; foreach ($encryptedFieldSegments as $encryptedFieldSegment) { if (!isset($valueReference[$encryptedFieldSegment])) { break; } $valueReference = &$valueReference[$encryptedFieldSegment]; $vaultCiphertext = strrev($valueReference[$encryptedField]); $valueReference[$encryptedField] = $vaultCiphertext; } unset($valueReference); } elseif (isset($controlValue[$encryptedField])) { $vaultCiphertext = strrev($controlValue[$encryptedField]); $controlValue[$encryptedField] = $vaultCiphertext; } } var_dump($controlValue);
Output for 5.6.38 - 7.3.0rc3
Warning: Illegal string offset 'item3.item5' in /in/VODih on line 33 Warning: Illegal string offset 'item3.item5' in /in/VODih on line 34 array(3) { ["item1"]=> string(4) "val1" ["item2"]=> string(4) "2lav" ["item3"]=> array(2) { ["item4"]=> string(4) "val4" ["item5"]=> string(4) "val5" } }