Ajeet Kurrey Ajeet Kurrey - 14 days ago 9
PHP Question

show the data from complex json data in php

Array
(
[category] => Array
(
[0] => Array
(
[id] => 15
[parent] => 11
[name] => Albums
[slug] => albums
[img_url] => http://playcontest.in/diy/wordpress/wp-content/uploads/2013/06/cd_5_angle.jpg
[count] => 4
[link] => http://playcontest.in/diy/wordpress/product-category/music/albums/
)

[1] => Array
(
[id] => 9
[parent] => 0
[name] => Clothing
[slug] => clothing
[img_url] => http://playcontest.in/diy/wordpress/wp-content/uploads/2013/06/hoodie_6_front.jpg
[count] => 12
[link] => http://playcontest.in/diy/wordpress/product-category/clothing/
)

[2] => Array
(
[id] => 10
[parent] => 9
[name] => Hoodies
[slug] => hoodies
[img_url] => http://playcontest.in/diy/wordpress/wp-content/uploads/2013/06/hoodie_6_front.jpg
[count] => 6
[link] => http://playcontest.in/diy/wordpress/product-category/clothing/hoodies/
)



)

[meta_data] => Array
(
[tz] => Europe/London
[c] => INR
[c_f] => ?
[t_i] =>
[w_u] => lbs
[d_u] => in
[d_s] => .
[t_s] => ,
[p_d] => 2
[c_p] => left
[cart_url] => http://playcontest.in/diy/wordpress/cart/
[checkout_url] => http://playcontest.in/diy/wordpress/checkout/
[hide_out_of_stock] => no
)

[best_selling] => Array
(
[0] => Array
(
[stock] => 1
[url] => http://playcontest.in/diy/wordpress/product/woo-album-4/
[desc] => Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. Vestibulum tortor quam, feugiat vitae, ultricies eget, tempor sit amet, ante. Donec eu libero sit amet quam egestas semper. Aenean ultricies mi vitae est. Mauris placerat eleifend leo.
[title] => Woo Album #4
[id] => 96
[img] => http://playcontest.in/diy/wordpress/wp-content/uploads/2013/06/cd_5_angle.jpg
[type] => simple
[price] => 9
[regular_price] => 9
[sale_price] =>
[category_ids] => Array
(
[0] => 15
[1] => 11
)

[created_at] => 2013-06-07 11:37:23
[average_rating] => 5.00
[total_sales] => 23
[featured] =>
)

[1] => Array
(
[stock] => 1
[url] => http://playcontest.in/diy/wordpress/product/woo-single-2/
[desc] => Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. Vestibulum tortor quam, feugiat vitae, ultricies eget, tempor sit amet, ante. Donec eu libero sit amet quam egestas semper. Aenean ultricies mi vitae est. Mauris placerat eleifend leo.
[title] => Woo Single #2
[id] => 99
[img] => http://playcontest.in/diy/wordpress/wp-content/uploads/2013/06/cd_6_angle.jpg
[type] => simple
[price] => 2
[regular_price] => 3
[sale_price] => 2
[category_ids] => Array
(
[0] => 11
[1] => 13
)

[created_at] => 2013-06-07 11:38:12
[average_rating] => 4.50
[total_sales] => 6
[featured] =>
)



)

[new_arrivals] => Array
(
[0] => Array
(
[stock] => 1
[url] => http://playcontest.in/diy/wordpress/product/woo-single-2/
[desc] => Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. Vestibulum tortor quam, feugiat vitae, ultricies eget, tempor sit amet, ante. Donec eu libero sit amet quam egestas semper. Aenean ultricies mi vitae est. Mauris placerat eleifend leo.
[title] => Woo Single #2
[id] => 99
[img] => http://playcontest.in/diy/wordpress/wp-content/uploads/2013/06/cd_6_angle.jpg
[type] => simple
[price] => 2
[regular_price] => 3
[sale_price] => 2
[category_ids] => Array
(
[0] => 11
[1] => 13
)

[created_at] => 2013-06-07 11:38:12
[average_rating] => 4.50
[total_sales] => 6
[featured] =>
)

[1] => Array
(
[stock] => 1
[url] => http://playcontest.in/diy/wordpress/product/woo-album-4/
[desc] => Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. Vestibulum tortor quam, feugiat vitae, ultricies eget, tempor sit amet, ante. Donec eu libero sit amet quam egestas semper. Aenean ultricies mi vitae est. Mauris placerat eleifend leo.
[title] => Woo Album #4
[id] => 96
[img] => http://playcontest.in/diy/wordpress/wp-content/uploads/2013/06/cd_5_angle.jpg
[type] => simple
[price] => 9
[regular_price] => 9
[sale_price] =>
[category_ids] => Array
(
[0] => 15
[1] => 11
)

[created_at] => 2013-06-07 11:37:23
[average_rating] => 5.00
[total_sales] => 23
[featured] =>
)

[2] => Array
(
[stock] => 1
[url] => http://playcontest.in/diy/wordpress/product/woo-single-1/
[desc] => Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. Vestibulum tortor quam, feugiat vitae, ultricies eget, tempor sit amet, ante. Donec eu libero sit amet quam egestas semper. Aenean ultricies mi vitae est. Mauris placerat eleifend leo.
[title] => Woo Single #1
[id] => 93
[img] => http://playcontest.in/diy/wordpress/wp-content/uploads/2013/06/cd_4_angle.jpg
[type] => simple
[price] => 0.01
[regular_price] => 0.01
[sale_price] =>
[category_ids] => Array
(
[0] => 11
[1] => 13
)

[created_at] => 2013-06-07 11:36:34
[average_rating] => 0.00
[total_sales] => 3
[featured] =>
)



)

[new_sales] => Array
(
[0] => Array
(
[stock] => 1
[url] => http://playcontest.in/diy/wordpress/product/flying-ninja/
[desc] => Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. Vestibulum tortor quam, feugiat vitae, ultricies eget, tempor sit amet, ante. Donec eu libero sit amet quam egestas semper. Aenean ultricies mi vitae est. Mauris placerat eleifend leo.
[title] => Flying Ninja
[id] => 70
[img] => http://playcontest.in/diy/wordpress/wp-content/uploads/2013/06/poster_2_up.jpg
[type] => simple
[price] => 12
[regular_price] => 15
[sale_price] => 12
[category_ids] => Array
(
[0] => 12
)

[created_at] => 2013-06-07 11:25:01
[average_rating] => 4.00
[total_sales] => 3
[featured] =>
)

[1] => Array
(
[stock] => 1
[url] => http://playcontest.in/diy/wordpress/product/premium-quality-2/
[desc] => Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. Vestibulum tortor quam, feugiat vitae, ultricies eget, tempor sit amet, ante. Donec eu libero sit amet quam egestas semper. Aenean ultricies mi vitae est. Mauris placerat eleifend leo.
[title] => Premium Quality
[id] => 73
[img] => http://playcontest.in/diy/wordpress/wp-content/uploads/2013/06/poster_3_up.jpg
[type] => simple
[price] => 12
[regular_price] => 15
[sale_price] => 12
[category_ids] => Array
(
[0] => 12
)

[created_at] => 2013-06-07 11:27:38
[average_rating] => 2.00
[total_sales] => 1
[featured] =>
)

[2] => Array
(
[stock] => 1
[url] => http://playcontest.in/diy/wordpress/product/ship-your-idea-2/
[desc] => Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. Vestibulum tortor quam, feugiat vitae, ultricies eget, tempor sit amet, ante. Donec eu libero sit amet quam egestas semper. Aenean ultricies mi vitae est. Mauris placerat eleifend leo.
[title] => Ship Your Idea
[id] => 40
[img] => http://playcontest.in/diy/wordpress/wp-content/uploads/2013/06/hoodie_7_front.jpg
[type] => variable
[price] => 30
[regular_price] =>
[sale_price] =>
[category_ids] => Array
(
[0] => 9
[1] => 10
)

[min_var_price] => 30
[max_var_price] => 35
[created_at] => 2013-06-07 11:00:28
[average_rating] => 4.00
[total_sales] => 0
[featured] =>
)



)

[payment] => Array
(
[gateways] => Array
(
[0] => Array
(
[id] => cheque
[title] => Cheque Payment
[description] => Please send your cheque to Store Name, Store Street, Store Town, Store State / County, Store Postcode.
[icon] =>
[chosen] =>
[order_button_text] =>
[enabled] => yes
[testmode] =>
[instructions] => Please send your cheque to Store Name, Store Street, Store Town, Store State / County, Store Postcode.
[account_details] => Array
(
)

[settings] => Array
(
)

)

[1] => Array
(
[id] => cod
[title] => Cash on Delivery
[description] => Pay with cash upon delivery.
[icon] =>
[chosen] =>
[order_button_text] =>
[enabled] => yes
[testmode] =>
[instructions] => Pay with cash upon delivery.
[account_details] => Array
(
)

[settings] => Array
(
[extra_charges] => 100
[extra_charges_msg] => COD Charges
[extra_charges_type] => amount
[cod_pincodes] => 12345,23456
[in_ex_pincode] => include
)

)

[2] => Array
(
[id] => cop
[title] => Cash on pickup
[description] => Pay your order in cash as you pick it up at our store.
[icon] =>
[chosen] =>
[order_button_text] => Place order
[enabled] => yes
[testmode] =>
[instructions] => Pay with cash on pickup at [Store address].
[account_details] => Array
(
)

[settings] => Array
(
)

)


)

)


)

Answer

Assuming that the "new arrivals count" as you call it is the number of elements in the "new_arrivals" array, this works:

$data = json_decode( ... your json string ... );
echo count($data->new_arrivals);

Edit: It's really hard to understand what you want. How about this?

echo "<table><tr>";
foreach ($data["new_arrivals"][0] as $key => $value) {
    if ($key == "category_ids") continue;
    echo "<th>" . $key . "</th>";
}
echo "</tr>";
foreach ($data["new_arrivals"] as $row) {
    echo "<tr>";
    foreach ($row as $key => $value) {
        if ($key == "category_ids") continue;
        echo "<td>" . $value . "</td>";
    }
    echo "</tr>";
}
echo "</table>";
Comments