【发布时间】:2015-09-15 09:27:55
【问题描述】:
我有这个forloop,它给了我一个数组结果,如下所示。但是json格式的结果很奇怪,它用完了。有人可以帮忙吗?尝试更改几种方法,但是当我将代码更改为$product_name[$prod_url][$i][$i] 时失败了,他们确实加入了,但没有给我产品名称,而是变为空。这样$product_name[$i][[$prod_url][$i]]就完全黑屏了。
{
0: {
0: {
order_item_name: "12345678"
},
Permalink: "https://localhost/Test/?post_type=post&p=80"
},
1: {
0: {
order_item_name: "asdasdasda"
},
Permalink: "https://localhost/Test/?post_type=post&p=79"
},
2: {
0: {
order_item_name: "test"
},
Permalink: "https://localhost/Test/?post_type=post&p=9"
},
3: {
0: {
order_item_name: "test222222"
},
Permalink: "https://localhost/Test/?post_type=post&p=76"
},
status: "ok"
}
循环
for($i = 0; $i < count($product_name); $i++){
$post_data[$i] = $product_name[$i]->order_item_name;
foreach ($post_data as $pd){
$pd = $wpdb->get_results("SELECT ID FROM $wpdb->posts WHERE post_title = '$post_data[$i]' ");
}
foreach($pd as $pdd){
$prod_url[] = get_post_permalink($pdd);
}
$data_array[$i] = array($product_name[$i],"Permalink" => $prod_url[$i]);
}
我怎样才能把它格式化成这样:或者更好的格式
{
0: {
Product Name: "12345678",
Permalink: "https://localhost/Test/?post_type=post&p=80"
},
1: {
Product Name: "asdasdasda",
Permalink: "https://localhost/Test/?post_type=post&p=79"
},
2: {
Product Name: "test",
Permalink: "https://localhost/Test/?post_type=post&p=9"
},
3: {
Product Name: "test222222",
Permalink: "https://localhost/Test/?post_type=post&p=76"
},
status: "ok"
}
【问题讨论】:
标签: php arrays json wordpress for-loop