【发布时间】:2011-09-10 05:56:36
【问题描述】:
我快疯了,花了几个小时尝试不同的方法来替换数组中的值,但我无法让它工作。
foreach($potentialMatches as $potentialKey)
{
$searchKeywordQuery = "SELECT keyword, id FROM picture WHERE id='$potentialKey'";
$searchKeywords = mysql_query($searchKeywordQuery) or die(mysql_error());
while ($searchKeyWordsRow = mysql_fetch_array($searchKeywords))
{
$keyword = $searchKeyWordsRow['keyword'];
$pictureKeywordArray[$searchKeyWordsRow['id']]['keywords'] = explode(",", $keyword);
$pictureKeywordArray[$searchKeyWordsRow['id']]['match'] = 4;
}
}
foreach($pictureKeywordArray as $key = > $picValue)
{
foreach($picValue['keywords'] as $key = > $picIdValue)
{
if ($picIdValue == $searchIdKey)
{
echo $picValue['match'];
$picValue['match']++;
echo $picValue['match'];
}
}
}
foreach($pictureKeywordArray as $key = > $picValue)
{
echo $picValue['match'];
}
如您所见,我是新手,当我在 foreach 循环中回显 picValue['match'] 时,它会在“++”之后给我一个正确的值。但是在下面当我再次调用数组时,它给了我 4 而不是 5 的值。在此先感谢您提供的任何帮助。
【问题讨论】:
标签: php arrays replace foreach