[英]Put increasing number before echo result array
Hi I want to loop through some items and output is like this: 嗨,我想遍历一些项目,输出是这样的:
"&product_url[1]=http://www.result1.com&product_url[2]=http://www.result2.com&product_url[3]=http://www.result3.com"
So loop through and put a increasing number in front of each items starting with 1. 因此循环遍历,并在每个项目的前面添加从1开始的数字。
Any idea? 任何想法?
// get order items details
$order_items = $order->get_items();
// loop through items in order
foreach ( $order_items as $order_item ) {
$product_link = get_permalink($product_id)
echo $product_link;
}
You can do like this: 您可以这样:
// get order items details
$counter = 1;
$url = "";
$order_items = $order->get_items();
// loop through items in order
foreach ( $order_items as $order_item ) {
$product_link = get_permalink($product_id)
$url .= "&product_url[$counter]=" . $product_link;
$counter ++;
}
echo $url; // <-- here you will have the url.
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.