1
I’m trying to remove an item from a array
corresponding to [NUMERO] but not working.
Array:
Array
(
[0] => Array
(
[NUMERO] => 123
[DATA] => 11/11/1111
[VALOR] => 2,22
[ARQUIVO] =>
)
[1] => Array
(
[NUMERO] => 456
[DATA] => 12/12/1212
[VALOR] => 33,33
[ARQUIVO] =>
)
)
Bolei this function to returns the KEY to then remove it:
function hasArrayKey( $array, $value ){
foreach( $array as $key => $temp ){
if( array_search( $value, $temp ) !== false ){
return $key;
}
}
return false;
}
Plus it removes the KEY "0" if it does not find:
$nota = hasArrayKey( $_SESSION['NOTAS'], '999' );
if( $nota >= 0 ){
unset( $_SESSION['NOTAS'][$nota] );
}
if( !$nota ){
echo "Nota not found\n";
}
Any ideas, guys?
You want to remove from the array by value or key ?
– gmsantos
Remove by [NUMBER value]
– smigol
Do you know if he is finding $key correct? ever tried to print $key?
– Édipo Costa Rebouças
Yes he thinks the KEY is right
– smigol
Related: http://answall.com/a/34790/7210
– Jorge B.