ok, not sure why this is not working
$info contains an array, there are 3 copies of user_pass that should all be removed, the first two are removed, but the third is not.
Any ideas?
if($phoneDetails['show_passwd'] == '0') {
for($i = 0; $i < count($info); $i++) {
if($info[$i]['header']['tag'] == 'user_pass') {
unset($info[$i]);
}elseif($info[$i]['header']['tag'] == 'http_pass') {
unset($info[$i]);
}
}
}
You code relies on the fact that the indices of the array go from 0
to N-1
. Is that really your case? What if you replaced the for
cycle with foreach
:
if ($phoneDetails['show_passwd'] == '0') {
foreach ($info as $i => $v) {
if ($info[$i]['header']['tag'] == 'user_pass']) {
unset($info[$i]);
} else if ($info[$i]['header']['tag'] == 'http_pass') {
unset($info[$i]);
}
}
}
Same code you given, but more refactored. btw I didn't get what you really need
if($phoneDetails['show_passwd'] == '0') { //or if(!$phoneDetails['show_passwd'])
$i = 0;
for($i; $i < count($info); $i++) {
$tag = !empty($info[$i]['header']['tag']) ? $info[$i]['header']['tag'] : '';
if ($tag == 'user_pass' || $tag == 'http_pass') {
unset($info[$i]);
}
}
}