我有一段使用不推荐使用的each()函数的代码。我试图用key()或current()替换它,但这只是破坏了我的PHP代码。我想念什么?
这是原始代码段:
echo '<div class="cards">';
$i = 0;
reset($cards);
while( (list($card_id, $card) = each($cards)) || $i < 30 ) {
if( isset($card_id) ) {
$name = "i$card_id";
$value = htmlspecialchars($card->label);
} else {
$name = $i;
$value = '';
}
echo '
<div class="card' . (isset($card_id) ? !strlen($card->file_name) ? ' without-image' : '' : ' empty') . '">
<div class="thumbnail">';
if( isset($card) && strlen($card->file_name)) {
echo '<img class="image-zoom" data-href="/assets/' . $testKey . '/' . $card->file_name . '" src="/assets/' . $testKey . '/' . file_name_append($card->file_name, '_s') . '">';
}
echo '</div>';
echo '<input type="text" class="label" name="cardsLabel[' . $name . ']" value="' . $value . '">';
echo '<input type="file" size="4" class="image" name="cardsImage[' . $name . ']">';
echo '<span class="remove-dupe uico ui-icon-closethick" onclick="card_form_remove_duplicate(this);"></span>';
echo "</div>\n";
++$i;
}
echo '</div>';