donglu7286
donglu7286
2013-05-24 05:23

如何从数据数组中获取特定值? [关闭]

已采纳

I am trying to fetch specific data from the array of data but not able to get proper output. Please guide me.

Code

echo "<pre>";
    $cart = VirtueMartCart::getCart();
    $cmpny=$cart->BT;
    print_r($cmpny);

    $i=0;
    foreach($cmpny as $data)
    {
        if(true)
        {
        echo $data."
";
        }
        $i++;

    }
    exit;   

Output What I am Getting

Output What I am Getting

How could i able to fetch only [company] or only any single element.... i had try to access with

 $data->company

but not able to fetch.... so please guide me....

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 复制链接分享
  • 邀请回答

3条回答

  • duanchuaiwan0063 duanchuaiwan0063 8年前

    Hello Please try this

    foreach($cmpny as $data)
    {          
       echo $data['company']."
    ";
    }
    

    I think you got result as company data

    点赞 评论 复制链接分享
  • dongying6896 dongying6896 8年前

    $data->company can only be used if the $data is an object, to access elements in array, you should use $data['company']

    点赞 评论 复制链接分享
  • dtwzwmv87399 dtwzwmv87399 8年前

    You have array as result, so you should use array access instead of property access: $data['company']

    点赞 评论 复制链接分享

相关推荐