Php 使用数组拼接交换数组的最后一个值?
我有一个数组,看起来是这样的:Php 使用数组拼接交换数组的最后一个值?,php,arrays,magento,array-splice,Php,Arrays,Magento,Array Splice,我有一个数组,看起来是这样的: Array ( [0] => Credit Card Type [1] => MasterCard ) Array ( [0] => Credit Card Number [1] => xxxx-1111 ) Array ( [0] => Processed Amount [1] => $106.91 ) Array ( [0] => Transaction Id [1] => 5011056094736597703
Array ( [0] => Credit Card Type [1] => MasterCard )
Array ( [0] => Credit Card Number [1] => xxxx-1111 )
Array ( [0] => Processed Amount [1] => $106.91 )
Array ( [0] => Transaction Id [1] => 5011056094736597703015 )
Array ( [0] => AVS Response [1] => Z (Street address does not match, but 5-digit postal code matches.) )
Array ( [0] => CVN Response [1] => M (Card verification number matched.) )
Array ( [0] => Merchant Reference Code [1] => 25f11646823dc7488b48c04491335936 )
我正在使用print\r(数组($\u标签,$\u值))代码>以显示上述内容
我想交换掉商户参考代码值,它是一个长字母数字
这是一个magento构建,所以我想我会回应
$order = Mage::getModel('sales/order')->load($orderId);
echo $order->getIncrementId();
完成工作最合适的方式是什么
阵列拼接
或阵列推送
任何帮助都将不胜感激。多谢各位
<div class="cards-list">
<?php if (!$this->getHideTitle()): ?>
<div class="bold"><?php echo $this->escapeHtml($this->getMethod()->getTitle()) ?></div>
<?php endif;?>
</div>
<?php
$cards = $this->getCards();
$showCount = count($cards) > 1;
?>
<?php foreach ($cards as $key => $card): ?>
<?php if ($showCount): ?>
<span><?php echo sprintf($this->__('Credit Card %s'), $key + 1); ?></span>
<?php endif;?>
<table class="info-table<?php if ($showCount):?> offset<?php endif;?>">
<tbody>
<?php foreach ($card as $_label => $_value):?>
<tr>
<td><?php echo $this->escapeHtml($_label)?>:</td>
<td><?php echo nl2br(implode($this->getValueAsArray($_value, true), "\n"))?></td>
</tr>
<?php endforeach; ?>
</tbody>
</table>
<?php endforeach; ?>
好的,根据您提供的print\r输出,我将假设您正在遍历一个数组,该数组看起来如下,并打印键($\u标签)和值($\u值)
那么,为什么不干脆取消商户参考代码密钥的设置,并在数组中添加所需的密钥/值呢。例如:
unset($data['Merchant Reference Code']);
$data['Order Id'] = $order->getIncrementId();
我认为你可以取代:
<?php foreach ($card as $_label => $_value):?>
<tr>
<td><?php echo $this->escapeHtml($_label)?>:</td>
<td><?php echo nl2br(implode($this->getValueAsArray($_value, true), "\n"))?></td>
</tr>
<?php endforeach; ?>
与
使转换文件在app/code/{pool}/My/Module/ect/config.xml
中可用,将其添加到global
、frontend
或adminhtml
部分
<translate>
<modules>
<My_Module>
<files>
<default>My_Module.csv</default>
</files>
</My_Module>
</modules>
</translate>
您能否澄清“调出”是什么意思。根据您对array_splice的引用,我假设您希望删除“商户参考代码”元素,并添加另一个具有订单id的元素?这是正确的@ever.wakefull能否请您添加生成$\u标签和$\u值的代码?
?当然@sv3n我现在就这样做。这会破坏页面。请解释最后一部分$this->u u()。当我用上面的代码测试它时,它会破坏页面的下半部分。也许我做错了什么?我想这取决于你在哪里添加的代码。很难判断您正在处理的部分代码。在哪里调用Mage::getModel('sales/order')->load($orderId)?
<?php foreach ($card as $_label => $_value): ?>
<?php if ($_label === 'Merchant Reference Code') {
continue;
} ?>
<tr>
<td><?php echo $this->escapeHtml($_label)?>:</td>
<td><?php echo nl2br(implode($this->getValueAsArray($_value, true), "\n"))?></td>
</tr>
<?php endforeach; ?>
<tr>
<td>Order ID:</td>
<td><?php echo $order->getIncrementId();?></td>
</tr>
<?php if ($_label === 'Merchant Reference Code') {
<?php if ($_label === $this->__('Merchant Reference Code')) {
"Merchant Reference Code";"Translate string"
<translate>
<modules>
<My_Module>
<files>
<default>My_Module.csv</default>
</files>
</My_Module>
</modules>
</translate>
class My_Module_Helper_Data extends Mage_Core_Helper_Abstract
{
protected $_moduleName = 'My_Module';
}