【问题标题】:Storing array in session在会话中存储数组
【发布时间】:2016-11-04 09:44:53
【问题描述】:

我正在尝试在 WordPress 中处理数组的内容,然后将数组存储在会话中,数组输出如下;

Array
(
    [0] => yes
    [1] => no
)

但是在 $wp_session['test_array'] 中存储后,它的输出类似于;

Recursive_ArrayAccess Object
(
[container:protected] => Array
    (
        [0] => yes
        [1] => no
    )

[dirty:protected] => 1
)

有什么建议可以将数组恢复为原始格式,以便我可以轻松处理。

为任何帮助干杯

【问题讨论】:

    标签: arrays session


    【解决方案1】:

    您可以在存储之前通过序列化()数组并在检索时取消序列化()。

    例如:

    $wp_session['test_array'] = serialize( array( 'yes', 'no' ) );
    $test_array = unserialize( $wp_session['test_array'] );
    print_r( $test_array );
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2014-01-23
      • 2018-12-09
      • 2016-09-17
      • 2021-06-21
      相关资源
      最近更新 更多