如何在php中的查询字符串上传递数组值 [英] How to Pass the array values on query string in php

查看:61
本文介绍了如何在php中的查询字符串上传递数组值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要您的帮助。

如何在查询字符串中传递数组值...

How to pass the array values in query string...

<?php 
                foreach ( $Cart->getItems() as $order_code=>$quantity ) :
                $pname[]= $Cart->getItemName($order_code);
                $item[]= $Cart->getItemPrice($order_code);
                $qty[]=$quantity;
                endforeach;
                ?>
                <form action='expresscheckout.php?amt=<?php echo $total_price; ?>&item_name=<?php echo $pname; ?>&unit=<?php echo $item; ?>&quan=<?php echo $qty; ?>' METHOD='POST'>
<input type='image' name='submit' src='https://www.paypal.com/en_US/i/btn/btn_xpressCheckout.gif' border='0' align='top' alt='Check out with PayPal'/>
</form>

这是我的代码示例。对于上面的示例代码,我必须将查询字符串传递给我操作网址是expresscheckout.php?amt = 100.,etc ...值位于$ pname [],$ item [],$ qty []下。

This is my code sample.,for the above sample code i have to pass the query string on my action url that is expresscheckout.php?amt=100.,etc...values are coming under the $pname[],$item[],$qty[].

在expresscheckout.php中期望输出

expresscheckout.php?pname = product1,product2& item = item1,item2& qty = 1, 2,3 .... this ....

expresscheckout.php?pname=product1,product2&item=item1,item2&qty=1,2,3....like this....

在此先感谢...。

推荐答案

基本上,您只需要使用PHP的内嵌函数可将数组转换为以逗号分隔的列表。即对于$ item数组:

Basically, you just need to use PHP's implode function to turn an array into a comma-separated list. i.e. for the $item array:

$item = array('item1', 'item2');
echo implode(',', $item);

会输出:

item1,item2

因此,类似这样的内容应打印类似于以下内容的查询字符串您需要:

So, something like this should print a querystring similar to what you want:

echo 'pname='.implode(',', $pname).
     '&item='.implode(',', $item).
     '&qty='.implode(',', $qty);

这篇关于如何在php中的查询字符串上传递数组值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆