PHP中的JSON解码数组


JSON decoded array in PHP

在Url调用中,我得到了这种类型的数据。我想获取"coupon_title"值

Array ( [success] => 1 
[data] => Array ( 
[0] => Array ( 
[0] => Array ( [featured] => [exclusive] => [promo_id] => P11757 
           [offer_id] => 412 [offer_name] => Flipkart.com CPS - India 
           [coupon_title] => Buy Sony Mobiles along with battery charger and get 20% OFF on battery charger 
           [coupon_type] => Promotion 
           [link] => http://tracking.vcommission.com/aff_c?offer_id=412&aff_id=27655&url=http%3A%2F%2Fwww.flipkart.com%2Fpromotion%2Fpr%3Foffer%3DMobile_combo_31.g1%26sid%3Dtyy%2C4io%26 
           [coupon_expiry] => 2015-12-31 [added] => 2014-08-26 ) 
$coupon_title = $data['data'][0][0]['coupon_title'];

它一定是类似的东西

$array['data']['0']['0']['coupon_title']

我没有测试,但它会像它一样。

干杯!

将您的数组作为$mainArray 传递

 $res = array();
    array_walk_recursive($mainArray, function($item,$key){
               global $res;
               $res[$key] = $item;
    });
    echo "<pre>".print_r($res)."</pre>";
    echo $res["coupon_title"];