gpt4 book ai didi

php - 如何打印key的数组值

转载 作者:行者123 更新时间:2023-11-29 18:19:49 26 4
gpt4 key购买 nike

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

    $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 ,那么输出就是您可以看到的数组列表。

 [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\"}]
)

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

最佳答案

您可以使用 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);

关于php - 如何打印key的数组值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46684245/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com