Ich habe zwei multidimensionale Array namens $ Array und $array1
, die Schlüssel und Werte sind dynamisch, ich bin in der Lage, die array_diff()
von $array
und $array1
zu finden und ich möchte die Array-Schlüssel als Tabelle Spalte Name und Array-Werte als Tabelle drucken Werte. Das eigentliche Problem ist, dass ich die Spalte, die keine Werte hat, nicht weglassen kann. Hier gebe ich einen Beispielcode, der fest codierte Array-Schlüssel und Werte hat.So entfernen Sie einen dynamischen mehrdimensionalen Arrayschlüssel, wenn dieses Array keine Werte enthält. mit php
<?php
error_reporting(0);
$array[0] = array("key1" => "valueNew", "key2" => "Array2", "key3" => "value3", "key4" => "value4");
$array[1] = array("key1" => "valuetwo", "key2" => "Array2", "key3" => "value3", "key4" => "value4");
$array[2] = array("key1" => "valueThree", "key2" => "Array2", "key3" => "value3", "key4" => "value4");
$array1[0] = array("key1" => "Array1", "key2" => "Array2", "key3" => "Array3", "key4" => "Array4");
$array1[1] = array("key1" => "Array1", "key2" => "Array2", "key3" => "Array3", "key4" => "Array4");
$array1[2] = array("key1" => "Array1", "key2" => "Array2", "key3" => "Array3", "key4" => "Array4");
for($i=0;$i<count($array);$i++){
$implode[$i]=array_diff($array[$i],$array1[$i]);
}
$arrayKeys=array_keys($array[0]);
?>
<table width="200" border="1">
<tr>
<?php
for($i=0;$i<count($arrayKeys);$i++){
?>
<th scope="col"><?php echo $arrayKeys[$i]; ?></th>
<?php
}
?>
</tr>
<tr>
<?php
for($i=0;$i<count($arrayKeys);$i++)
{
?>
<td><?php for($j=0;$j<count($implode);$j++)
{
echo $implode[$j][$arrayKeys[$i]]."<br>";
} ?></td>
<?php
}
?>
</tr>
</table>
* Das eigentliche Problem ist, dass ich die Spalte, die keine Werte enthält, nicht weglassen kann. * '$ Ar = array_filter ($ ar);' – splash58