【发布时间】:2014-06-15 14:56:14
【问题描述】:
我不是 PHP 专家,但我正在尝试在 PHP 中比较 2 个数组(数据库关系和架构),我需要检索这 2 个数组之间的差异,我正在使用这个 php 代码
<?php
function maxEntities($rela, $db){
$maxenty = array();
$found = false;
foreach ($rela as $valor1) {
print $valor1[0] . " | ";
}
print " <br \>";
foreach ($db as $valor2) {
print $valor2[0] . " | ";
}
$maxenty = array_diff($rela[0], $db[0]);
print " <br \> <br \>";
foreach ($maxenty as $valor) {
print " " . $valor;
}
}
这段代码给了我这个输出
Sale | Customer | Sale_Fee | Sale | Location | Sale | Sale | Sale_Iten | Product | Customer | Location | Sale_Iten | Sale_Fee | Region |
Customer | Customer_Type | Fee_Type | Location | Location_Type | Period | Product | Product_Type | Region | Sale | Sale_Fee | Sale_Iten | State |
Sale Customer_Cust_Id
我期望的输出是
期间、客户类型、状态、位置类型、产品类型和费用类型
我该如何解决我的问题?
我也试过foreach,但也给我一个错误的输出
foreach ($rela as $relaV) {
foreach ($db as $dbV) {
if ($dbV[0] == $relaV[0]) {
$found = true;
}
if (!$found) {
$found = false;
$maxenty[] = $dbV[0];
}
}
}
在这种情况下,我的输出是
Customer
Customer_Type
Fee_Type
Location
Location_Type
Period
Product
Product_Type
Region
客户、地区、位置在两个数组中
【问题讨论】:
-
向我们展示数组本身的样本。