0

二维阵列

我无法附上图片,所以请在链接中找到数组。我消除了这个数组的重复值。我使用了有点糟糕的技术。数组名称是$pap。这是代码

 `foreach ($pap as $key => $row)
 { 
 foreach ($row as $subkey => $subvalue)
 {       $p[$n]=$pap[$key][$subkey];
 $n++;
}
}
$unique = array_unique($p);
$n=0; $abc = array();
foreach ($unique as $key => $row){
$abc[$n]=$unique[$key]; $n++;
}
$m=0;
echo "<table align='center' border='2'>";
foreach ($pap as $key => $row)
{ 
echo "<tr>";
foreach ($row as $subkey => $subvalue)
{       
if($m<$n){
if($pap[$key][$subkey]==$abc[$m])   
{
echo "<td>";
echo $pap[$key][$subkey];
echo "</td>";
$m++;
}
}
}
echo "</tr>";
}
echo"</table>";`

任何更好的技术将不胜感激。

4

1 回答 1

0

检查一下,我认为这将为您完成工作。

<?php

$details = array( 
    0 => array("id"=>"1", "name"=>"Mike",    "num"=>"9876543210"), 
    1 => array("id"=>"2", "name"=>"Carissa", "num"=>"08548596258"), 
    2 => array("id"=>"1", "name"=>"Mathew",  "num"=>"784581254"), 
); 

function super_unique($array)
{
  $result = array_map("unserialize", array_unique(array_map("serialize", $array)));

  foreach ($result as $key => $value)
  {
    if ( is_array($value) )
    {
      $result[$key] = super_unique($value);
    }
  }

  return $result;
}

var_dump(super_unique($details));
?>
于 2017-07-10T06:43:43.803 回答