PHP如何从数组中获取特定值并存储在`$\会话中`
我有一个数组,我想在其中获取一个特定的值(“已创建”),然后将im aPHP如何从数组中获取特定值并存储在`$\会话中`,php,arrays,session,Php,Arrays,Session,我有一个数组,我想在其中获取一个特定的值(“已创建”),然后将im a$\u SESSION存储在一个新数组中。我怎样才能做到这一点 我的数组看起来像这样 Array ( [0] => Array ( [product_id] => 679 [quantity] => 1 [created] => 2018-10-01
$\u SESSION
存储在一个新数组中。我怎样才能做到这一点
我的数组看起来像这样
Array
(
[0] => Array
(
[product_id] => 679
[quantity] => 1
[created] => 2018-10-01
)
[1] => Array
(
[product_id] => 677
[quantity] => 1
[created] => 2018-10-05
)
[2] => Array
(
[product_id] => 678
[quantity] => 1
[created] => 2018-10-03
)
)
我试过这样的方法:
foreach($created as $i) {
$values = [$i]['created'];
echo $values;
}
session_start();
$_SESSION['creation_dates'] = $values;
但这不起作用
有人能帮我吗?在任何输出之前,您需要首先启动会话。您的
echo
s正在阻止这种情况。您必须收到通知
,但根据您的错误报告
看不到这些通知
请尝试以下代码:
session_start();
$values = array();
foreach($creation_dates as $i) {
$values[] = $i['created'];
}
$_SESSION['creation_dates'] = $values;
print_r($values);
print_r($_SESSION['creation_dates']);