php数组未给出结果i';我期待着
我真的被这件事困住了,我尝试了很多不同的方法,但我无法得到我所需要的,以使这件事成功。求你了,你能告诉我出了什么问题,这样我才能工作 在尝试建立一个属性网站时,上传了一个文件(.blm),我需要将该文件中的代理_REF放入一个数组中,以便与数据库进行比较,并显示数组差异。。。.blm文件包含信息代理\u REF^地址\u 1^地址\u 2^邮政编码1^邮政编码2 我确信是代理REF工作不正常,无法得到我需要的结果 请帮我解决这个问题php数组未给出结果i';我期待着,php,mysql,arrays,array-difference,Php,Mysql,Arrays,Array Difference,我真的被这件事困住了,我尝试了很多不同的方法,但我无法得到我所需要的,以使这件事成功。求你了,你能告诉我出了什么问题,这样我才能工作 在尝试建立一个属性网站时,上传了一个文件(.blm),我需要将该文件中的代理_REF放入一个数组中,以便与数据库进行比较,并显示数组差异。。。.blm文件包含信息代理\u REF^地址\u 1^地址\u 2^邮政编码1^邮政编码2 我确信是代理REF工作不正常,无法得到我需要的结果 请帮我解决这个问题 <?php $rmdata = $rmparser-&
<?php
$rmdata = $rmparser->getPropertyData();
$properties = array();
foreach ($rmdata as $properties) {
$fields = array();
$values = array();
$blmarArray = array();
foreach ($properties as $field=>$value) {
if (!$value) continue;
$blmarArray = $values[0];
$agentref = $values[0];
$fields[] = $field;
$values[] = "'".$value."'";
}
$sql_archeck = mysql_query("SELECT `AGENT_REF` FROM `eprentals`");
$sqlarArray = array();
while($row = mysql_fetch_array($sql_archeck)) {
$sqlarArray[] = $row['AGENT_REF'];
}
$combyArrayDiff = array_diff($sqlarArray, $blmarArray);
echo '
<div style="background-color:#ffd7d7;border:#bcbcbc solid 1px;padding:6px;margin- bottom:6px;">
<span style="padding:2px;"><p><b>SQL list:</b> ' . implode(', ', $sqlarArray) . '</p></span>
<p><b>Uploaded list:</b> ' . implode(', ', $blmarArray) . '</p>
<p><b>Diff list:</b> ' . implode(', ', $combyArrayDiff ) . '</p>
</div>
';
}
以下是您的代码现在的作用:
/* load rmdata */
$rmdata = $rmparser->getPropertyData();
/* make $properties an empty array */
$properties = array();
/* foreach rmdata, replace $properties with the current rmdata */
foreach ($rmdata as $properties)
{
/* replace 3 variables with empty arrays */
$fields = array();
$values = array();
$blmarArray = array();
/* for each property */
foreach ($properties as $field=>$value)
{
/* if the propery don't have a value */
if (!$value)
/* skip this property */
continue;
/* if the propery have a value */
/* replace $blmarArray and $agentref with the first row in $values, always empty for first property */
$blmarArray = $values[0];
$agentref = $values[0];
/* add current field to the fields array */
$fields[] = $field;
/* add current value (suronded by ') to the values array */
$values[] = "'".$value."'";
}
/* if there was at least 2 properties with values */
/* $blmarArray and $agentref have the value of the first of them */
}
我想这就是你想要做的:
/* create 2 empty arrays */
$rm_agentrefs = array();
$db_agentrefs = array();
/* fetch rmdata */
$rmdata = $rmparser->getPropertyData();
/* foreach rmdata */
foreach($rmdata as $current_row)
{
/* store the Agent Ref in the rm-array */
$rm_agentrefs[] = $current_row['AGENT_REF'];
}
/* define a database query for fetching agent ref from database */
$db_query = "SELECT `AGENT_REF` FROM `eprentals`";
/* run the database query */
$db_resource = mysql_query($db_query);
/* fetch each line from the resource */
while($current_row = mysql_fetch_array($db_resource))
{
/* store each agent ref in the db-array */
$db_agentrefs[] = $current_row['AGENT_REF'];
}
/* compare db and rm arrays (missing = db - rm) */
$missing_agentrefs = array_diff($db_agentrefs, $rm_agentrefs);
当您使用var_dump($row)时会得到什么?您应该在询问之前重新研究您的代码。请看第二条foreach指令:foreach($field=>$value的属性){if(!$value)continue;$blmar=$values[0];}为什么要检索$field中的键,然后不使用它们$blmar是作为一个数组创建的,但在这个循环中,您会继续重新定义它的内容。也许你想做一些类似$blmar[$field]=$value的事情,$rmdata
看起来像什么,请注意添加该值的var_dump($rmdata)或var_export($rmdata)我删除了一些行,因为我认为它太多了:)现在更新以显示大部分代码:)嗨,普根,谢谢你的更新。。。在我看来,$blmarArray应该具有每个属性的AGENT_REF的值。但是我不能得到数组,所以我可以做一个数组差异。。mysql中的数组生成正确的字段adn这就是为什么我认为$BLMARRAY中的数组没有返回我需要的blm文件中的结果。我们需要知道$rmdata结构是什么样子的,为了帮助您正确执行此操作,请按照@DonSeba的说法执行!非常感谢。非常感谢Puggen,如果你看一下链接,它显示了需要的结果,虽然更多,但它有需要显示的结果。非常感谢你,我非常感谢你的帮助和帮助。所有分类的Puggen,再次,请让我感谢你的时间和帮助。我非常感谢你的帮助!非常感谢。