难以理解wordpress插件数据

时间:2016-07-10 15:34:37

标签: wordpress

我是wordpress世界的初学者。我很难从以下数据中检索预期值。

Array
(
    [0] => stdClass Object
        (
            [id] => 1
            [name] => MCQ Botany 101
            [settings] => a:24:{s:9:"limit_one";s:2:"no";s:12:"limit_one_wp";s:2:"no";s:16:"limit_one_cookie";s:2:"no";s:11:"save_resume";s:2:"no";s:16:"question_numbers";s:3:"yes";s:5:"timer";s:4:"5000";s:9:"pass_mark";s:2:"80";s:17:"show_progress_bar";s:3:"yes";s:20:"automark_whenfreetxt";s:2:"no";s:14:"finish_display";s:11:"Quiz Review";s:6:"status";s:7:"enabled";s:9:"send_user";s:2:"no";s:7:"contact";s:2:"no";s:6:"use_wp";s:2:"no";s:16:"notificaton_type";s:7:"instant";s:14:"email_template";s:0:"";s:12:"pdf_template";s:0:"";s:7:"use_pdf";s:2:"no";s:13:"store_results";s:3:"yes";s:18:"notification_email";s:0:"";s:14:"finish_message";s:0:"";s:11:"pass_finish";s:2:"no";s:19:"pass_finish_message";s:0:"";s:11:"fail_review";s:3:"yes";}
            [type] => quiz
            [timestamp] => 2016-07-10 21:02:44
        )
)

我希望来自s:4:"5000"的5000。任何帮助将受到高度赞赏。

2 个答案:

答案 0 :(得分:1)

你有一个数组,它有一个对象作为第一个键。你想获得一个设置'来自此对象的值,但它是一个序列化字符串。所以你需要先unserialize

假设$myArr是给定的数组,您将执行以下操作:

$settingsArr = unserialize($myArr[0]->settings);

$settingsArr['timer'];

因为timer键包含5000值。

您可以在php sandbox中重新创建:

<?php

$myObj = new stdClass;
$myObj->id = 1;
$myObj->name = 'MCQ Botany 101';
$myObj->settings = 'a:24:{s:9:"limit_one";s:2:"no";s:12:"limit_one_wp";s:2:"no";s:16:"limit_one_cookie";s:2:"no";s:11:"save_resume";s:2:"no";s:16:"question_numbers";s:3:"yes";s:5:"timer";s:4:"5000";s:9:"pass_mark";s:2:"80";s:17:"show_progress_bar";s:3:"yes";s:20:"automark_whenfreetxt";s:2:"no";s:14:"finish_display";s:11:"Quiz Review";s:6:"status";s:7:"enabled";s:9:"send_user";s:2:"no";s:7:"contact";s:2:"no";s:6:"use_wp";s:2:"no";s:16:"notificaton_type";s:7:"instant";s:14:"email_template";s:0:"";s:12:"pdf_template";s:0:"";s:7:"use_pdf";s:2:"no";s:13:"store_results";s:3:"yes";s:18:"notification_email";s:0:"";s:14:"finish_message";s:0:"";s:11:"pass_finish";s:2:"no";s:19:"pass_finish_message";s:0:"";s:11:"fail_review";s:3:"yes";}';
$myObj->type = 'quiz';
$myObj->timestamp = '2016-07-10 21:02:44';

$myArr = array(
    '0' => $myObj
);

$settingsArr = unserialize($myArr[0]->settings);

print_r($settingsArr['timer']);

您还可以看到设置数组的内容

print_r($settingsArr);

Array
(
    [limit_one] => no
    [limit_one_wp] => no
    [limit_one_cookie] => no
    [save_resume] => no
    [question_numbers] => yes
    [timer] => 5000
    [pass_mark] => 80
    [show_progress_bar] => yes
    [automark_whenfreetxt] => no
    [finish_display] => Quiz Review
    [status] => enabled
    [send_user] => no
    [contact] => no
    [use_wp] => no
    [notificaton_type] => instant
    [email_template] => 
    [pdf_template] => 
    [use_pdf] => no
    [store_results] => yes
    [notification_email] => 
    [finish_message] => 
    [pass_finish] => no
    [pass_finish_message] => 
    [fail_review] => yes
)

答案 1 :(得分:0)

我知道你的意思。如果您从未使用过这些序列化字符串,则很难找到它们。

请查看:

有关详细信息,请访问PHP手册:http://php.net/manual/en/function.serialize.php

我认为这应该可以帮助您重新序列化并再次序列化它们。