Código PHP:
<?php
/* Our Array of products */
$attribs[] = array(
"name" => "Test Product 1",
"length" => "42 cm",
"weight" => "0,5 kg",
"price" => "10 $",
"stock" => "100",
);
$attribs[] = array(
"name" => "Test Product 2",
"length" => "42 cm",
"weight" => "1,5 kg",
"price" => "10 $",
"stock" => "200",
);
/* The nice stuff */
$new = array();
$exclude = array("");
for ($i = 0; $i<=count($attribs)-1; $i++) {
if (!in_array(trim($attribs[$i]["price"]) ,$exclude)) { $new[] = $attribs[$i]; $exclude[] = trim($attribs[$i]["price"]); }
}
print_r($new); // $new is our sorted array
?>
Esta me gusta mucho mas!!
también la pueden usar como funcion!!
Código PHP:
public function array_elimina_duplicados($array, $campo)
{
$new = array();
$exclude = array("");
for ($i = 0; $i<=count($array)-1; $i++) {
if (!in_array(trim($array[$i][$campo]) ,$exclude)) { $new[] = $array[$i]; $exclude[] = trim($array[$i][$campo]); }
}
return $new;
}
saludos,