php - how to fetch value from array_chunk function -


i'm using array_chunk function:

<?php        $chunks = array_chunk($coupons, 2,true);     ?>  @foreach($chunks $k => $c ) @if(2 == sizeof($c))     $c[0]['tr']->coupon_code 

but blow code not works fine :

$c[0]['tr']->coupon_code  or  $c[0]['tr']['coupon_code'] 

the content of var_dump($c):

array(2) { [217517]=> array(3) { ["tr"]=> object(stdclass)#71 (30) { ["id"]=> string(6) "217517" ["price"]=> string(5) "14400" ["date"]=> string(19) "2016-01-16 11:13:13" ["user_id"]=> string(5) "16433" ["ip"]=> string(14) "46.225.196.181" ["code"]=> string(13) "5699f4917b9c3" ["succ"]=> string(1) "1" ["admin_seen"]=> string(1) "0" ["user_seen"]=> string(1) "0" ["coupon_id"]=> string(5) "15373" ["coupon_parent"]=> string(5) "15315" ["coupon_code"]=> string(20) "24_1117c1_4644(1453)" ["coupon_code_user"]=> string(4) "1453" ["coupon_code_partner"]=> string(14) "24_1117c1_4644" ["shop_id"]=> string(4) "1117" ["payment_type"]=> string(1) "7" ["merchent_type"]=> string(1) "3" ["merchent_id"]=> string(1) "0" ["cradit_start_date"]=> string(19) "2015-12-29 05:05:05" ["cradit_end_date"]=> string(19) "2016-02-19 05:05:05" ["expired"]=> string(1) "0" ["pay_data"]=> null ["seri"]=> string(1) "c" ["to_friend"]=> string(1) "0" ["finance_id"]=> string(1) "0" ["app"]=> string(3) "web" ["expire_date"]=> string(19) "0000-00-00 00:00:00" ["expire_app"]=> string(0) "" ["buy_id"]=> string(13) "5699f4913103e" ["coupon_property_id"]=> string(3) "195" } ["offer"]=> object(stdclass)#67 (46) { ["id"]=> string(5) "15373" ["title"]=> string(21) "طرح دخترانه" ["slider_title"]=> string(0) "" ["short_title"]=> string(0) "" ["pic"]=> string(25) "bracelets-off-greek31.jpg" ["text"]=> string(0) "" ["attrs"]=> string(0) "" ["jest"]=> string(0) "" ["terms_of_use"]=> string(0) "" ["how_to_use"]=> string(0) "" ["city"]=> string(0) "" ["price"]=> string(5) "45000" ["off"]=> string(2) "68" ["min_users"]=> string(1) "0" ["max_users"]=> string(1) "0" ["current_users"]=> string(1) "2" ["expire"]=> string(1) "0" ["sell_start_date"]=> string(19) "2015-12-29 01:00:00" ["sell_end_date"]=> string(19) "2016-01-26 15:00:00" ["cradit_start_date"]=> string(19) "0000-00-00 00:00:00" ["cradit_end_date"]=> string(19) "0000-00-00 00:00:00" ["admin_expire_date"]=> string(19) "0000-00-00 00:00:00" ["showin_other"]=> string(1) "0" ["showin_slider"]=> string(1) "0" ["showin_slider_cat"]=> string(1) "0" ["moment"]=> string(1) "0" ["seri"]=> string(1) "c" ["shop_id"]=> string(4) "1117" ["tractions"]=> string(1) "0" ["status"]=> string(1) "0" ["url"]=> string(0) "" ["shadyab_profit"]=> string(4) "6400" ["fake_sell"]=> string(1) "3" ["confirm"]=> string(1) "0" ["adviser"]=> string(1) "0" ["parent"]=> string(5) "15315" ["description"]=> string(0) "" ["old"]=> string(1) "0" ["email_text"]=> string(0) "" ["zone"]=> string(0) "" ["views"]=> string(1) "0" ["max_buy"]=> string(1) "0" ["likes"]=> string(1) "0" ["alt"]=> string(70) "فروشگاه گیوا گالری, خرید اینترنتی کالا" ["sizes"]=> string(0) "" ["name"]=> string(11) "مدل ها" } ["details"]=> object(stdclass)#66 (22) { ["id"]=> string(6) "205585" ["tr_id"]=> string(6) "217517" ["title"]=> string(59) "دستبند چرم پلاک استیل طرح فانتزی" ["short_title"]=> string(0) "" ["pic"]=> string(17) "dastband_(2)1.jpg" ["text"]=> string(627) " 

problem here preserve keys form original array. so, don't have 0 or 1 key in chunk $c.

either not preserve keys $chunks = array_chunk($coupons, 2) have id in tr object within id property , use $c[0]['tr']->coupon_code

or should keys of chunk $c array_keys example:

foreach($chunks $k => $c) {     $keys = array_keys($c);     echo $c[$keys[0]]['tr']->coupon_code; } 

Comments

Popular posts from this blog

c - How to retrieve a variable from the Apache configuration inside the module? -

c# - Constructor arguments cannot be passed for interface mocks -

python - malformed header from script index.py Bad header -