I'll assume that your $data
array have something like this:
$data['privacy'] = 'foo';
$data['privacy-something'] = 'bar';
$data['test'] = 'foobar';
In this situation strpos($key, 'privacy')
will not work correctly as if
statement will return false
for 0
value.
Also there was small brace problem at the end. So code that work perfectly for me looks like this:
$privacy = array();
foreach ($data as $key => $value) {
if (strpos($key, 'privacy') !== false) {
$privacy[$key] = $value;
unset($data[$key]);
}
}
EDIT
Problem is here:
else {
$data[$key] = $value;
}
You're setting unset value again. Why you need this?