如何打印键的数组值 [英] How can print array value of key

查看:41
本文介绍了如何打印键的数组值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我无法打印此查询返回的数组键的值:

I am unable to print value of array key returned by this query:

    $user1 = $wpdb->get_results(
        "select product,checked_by,date(submit_date) from diary_user_form_storage where DATE(submit_date) = CURDATE() ;
    ");

    $jsonString = "";
    foreach ($user1 as $key => $value) {
    $productString = stripslashes($value->product);
    $checked = stripslashes($value->checked_by);
    $suppliers = stripslashes($value->suppliers);
    $van_temperature = stripslashes($value->van_temperature);
    $comments = stripslashes($value->comments);
    $product = json_decode($productString, true);
    $checked_by = json_decode($checked , true);
    $suppliers = json_decode($suppliers , true);
    $van_temperature = json_decode($van_temperature, true);
    $comments = json_decode($comments, true);
//This code is running for single variable $product But I have to print all //multiple variable here . How can I print multiple variable here 

    foreach ($product as $v){
       echo  $v['product']; 
    }
}
?>

这是打印出来的结果

[1]=>
  array(1) {
    ["product"]=>
    string(5) "GSSHS"
  }
}

如果我为我的 SQL 查询 print_r($user1) 做了 print_r ,那么输出是你可以看到的数组列表.

If i did print_r for my SQL query print_r($user1) ,Then output is array list you can see.

 [1] => stdClass Object
        (
            [store_id] => 2
            [user_id] => 7
            [unit_data] => [{\"unit_data\":\"10\"}]
            [suppliers] => 
            [product] => [{\"product\":\"AA\"}]
            [checked_by] => [{\"checked_by\":\"Rakesh Kushwaha\"}]
            [temperature_in] => [{\"temperature_in\":\"QWW\"}]
            [temperature_out] => 
            [time_in] => [{\"time_in\":\"44:44\"}]
            [time_out] => 
            [van_temperature] => 
            [center_temperature] => 
            [cooling_temperature] => 
            [end_cooling_temperature] => 
            [comments] => 
            [submit_date] => 2017-10-18 22:12:39
            [time_holded] => 
            [temperature] => 
            [time_reheated] => 
            [extra_timing] => 
            [image_url] => 
            [category_name] => opening
            [category] => [{\"category\":\"Frozen\"}]
        )

我只需要数组的这个key的值:["product"]=>"GSSHS"

I only need the value of this key of array: ["product"]=>"GSSHS"

推荐答案

您可以使用 ARRAY_A

You can user ARRAY_A

$user1 = $wpdb->get_results(
    "select product,checked_by,date(submit_date) from diary_user_form_storage where DATE(submit_date) = CURDATE() ;
",ARRAY_A);

这篇关于如何打印键的数组值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆