For the logic you are trying to implement you can go through all the arrays you have inside the main and for each of them check if it contains the value you are looking for using the function array_search
. This function returns the key associated with the value or false
if it does not exist. When it exists and is not the first element you find assigns the value ''
to clean up.
Example of implementation:
function removerValoresDuplicadas(&$array, $valor){
$primeiroEncontrado = false;
for ($i = 0; $i < count($array); ++$i){
//obtem a chave associada ao valor ou false caso não exista nenhuma
$chave = array_search($valor, $array[$i]);
if ($chave !== false){ //se existe o valor
if ($primeiroEncontrado === false){ //caso especial para não limpar o primeiro
$primeiroEncontrado = true;
}
else {
$array[$i][$chave] = ''; //limpa
}
}
}
}
$dados = Array(
Array("forn_nome_fantasia" => "FORNECEDOR TESTE",
"class_nvl4_descricao" => "DESPESAS COM FRETES" ),
Array("forn_nome_fantasia" => "DJ/ DESEO -SALA DE ESTAR",
"class_nvl4_descricao" => "DESPESAS COM FRETES" )
);
removerValoresDuplicadas($dados, "DESPESAS COM FRETES");
print_r($dados);
Exit:
Array
(
[0] => Array
(
[forn_nome_fantasia] => FORNECEDOR TESTE
[class_nvl4_descricao] => DESPESAS COM FRETES
)
[1] => Array
(
[forn_nome_fantasia] => DJ/ DESEO -SALA DE ESTAR
[class_nvl4_descricao] =>
)
)
Note that I have built a function that receives the value you want to delete from the array to make it more flexible and be able to easily delete others you want
Example in Ideone
Put an example of the result to make it easier to understand your problem.
– Wictor Chaves
You want to check only this key "class_nvl4_description" or the other key "forn_name_fantasy"?
– Sam
Only the key
class_nvl4_descricao
– Leandro Lima