$conf, $runtime; function_exists('chdir') AND chdir(APP_PATH); $r = 'mysql' == $conf['cache']['type'] ? website_set('runtime', $runtime) : cache_set('runtime', $runtime); } function runtime_truncate() { global $conf; 'mysql' == $conf['cache']['type'] ? website_set('runtime', '') : cache_delete('runtime'); } register_shutdown_function('runtime_save'); ?>Add Array record to Meta Post|Programmer puzzle solving
最新消息:Welcome to the puzzle paradise for programmers! Here, a well-designed puzzle awaits you. From code logic puzzles to algorithmic challenges, each level is closely centered on the programmer's expertise and skills. Whether you're a novice programmer or an experienced tech guru, you'll find your own challenges on this site. In the process of solving puzzles, you can not only exercise your thinking skills, but also deepen your understanding and application of programming knowledge. Come to start this puzzle journey full of wisdom and challenges, with many programmers to compete with each other and show your programming wisdom! Translated with DeepL.com (free version)

Add Array record to Meta Post

matteradmin8PV0评论

I am trying to add the following array into the meta post table

"a:2:{s:11:"target";a:1:{i:0;a:1:{i:1;a:3:{s:5:"param";s:13:"page_selected";s:8:"operator";s:2:"==";s:5:"value";a:5:{i:3001;s:13:"Service Areas";i:1098;s:19:"Water Slide Rentals";i:672;s:15:"Chairs & Tables";i:205;s:4:"Home";i:1401;s:29:"Bounce House Rental Armada MI";}}}}s:15:"sgpb-conditions";N;}"

I broke down the array as follows

a:2:{  ##  ARRAY 1 [3 ELEMENTS]<br>
 -->KEY&nbsp;&nbsp;&nbsp;VALUE 1-1<br>
s:11:"target";&nbsp;&nbsp;&nbsp;a:1:{ ##  ARRAY 2 [2 ELEMENTS]<br><br>
 -->KEY&nbsp;&nbsp;&nbsp;VALUE 1-2 <br>
   i:0;&nbsp;&nbsp;&nbsp;a:1:{    ##  ARRAY 3 [2 ELEMENTS]<br><br>
 -->KEY&nbsp;&nbsp;&nbsp;VALUE 2-1 <br>
   i:1;&nbsp;&nbsp;&nbsp;a:3:{ ##  ARRAY 3 [4 ELEMENTS]<br><br>
 -->KEY&nbsp;&nbsp;&nbsp;VALUE 3-1 <br>
s:5:"param";&nbsp;&nbsp;&nbsp;s:13:"page_selected";<br><br>
 -->KEY&nbsp;&nbsp;&nbsp;VALUE 3-2 <br>
s:8:"operator";&nbsp;&nbsp;&nbsp;s:2:"==";<br><br>
 -->KEY&nbsp;&nbsp;&nbsp;VALUE 3-3 <br>
s:5:"value";&nbsp;&nbsp;&nbsp;a:5:{ ##  ARRAY 4 [6 ELEMENTS]<br><br>
 -->KEY&nbsp;&nbsp;&nbsp;VALUE 4-1 <br>
i:3001;&nbsp;&nbsp;&nbsp;s:13:"Service Areas";<br><br>
 -->KEY&nbsp;&nbsp;&nbsp;VALUE 4-2 <br>
i:1098;&nbsp;&nbsp;&nbsp;s:19:"Water Slide Rentals";<br><br>
 -->KEY&nbsp;&nbsp;&nbsp;VALUE 4-3 <br>
i:672;&nbsp;&nbsp;&nbsp;s:15:"Chairs & Tables";<br><br>
 -->KEY&nbsp;&nbsp;&nbsp;VALUE 4-4 <br>
i:205;&nbsp;&nbsp;&nbsp;s:4:"Home";<br><br>
 -->KEY&nbsp;&nbsp;&nbsp;VALUE 4-5 <br>
i:1401;&nbsp;&nbsp;&nbsp;s:29:"Bounce House Rental Armada MI";<br><br>

} <!-- ENDS ARRAY 5 --><br>
} <!-- ENDS ARRAY 4 --><br>
} <!-- ENDS ARRAY 3 --><br>
} <!-- ENDS ARRAY 2 --><br>
s:15:"sgpb-conditions";N;}  <!-- ENDS ARRAY 1 --><br>

^^^^^^^^^^^^^^^^^^^^^^^^^^

NOT SURE HOW THIS TIES IN

my question is about First issue I am having is a complete understanding of the array. Not sure how the last values tie into an array. Also, an Array is zero based correct?

Here is the code I have created so far to add the array, which is not creating the array correctly.

"<?php<br>
$poddata = Array(<br>
'sgpb-target',<br>
Array (<br>
    1 => Array(<br>
'param' => 'page_selected',<br>
'operator' => '==',<br>
'value' => Array(<br>
                3001 => 'Service Areas',<br>
                1098 => 'Water Slide Rentals',<br>
                672 => 'Chairs & Tables',<br>
                1401 => 'Bounce House Rental Armada MI',<br>
                676 => 'Mobile Gaming Trucks'<br>
                ))));<br>
<br>
update_post_meta(6668, 'poddata', $poddata);<br>
?>"  

Thanks for any help

I am trying to add the following array into the meta post table

"a:2:{s:11:"target";a:1:{i:0;a:1:{i:1;a:3:{s:5:"param";s:13:"page_selected";s:8:"operator";s:2:"==";s:5:"value";a:5:{i:3001;s:13:"Service Areas";i:1098;s:19:"Water Slide Rentals";i:672;s:15:"Chairs & Tables";i:205;s:4:"Home";i:1401;s:29:"Bounce House Rental Armada MI";}}}}s:15:"sgpb-conditions";N;}"

I broke down the array as follows

a:2:{  ##  ARRAY 1 [3 ELEMENTS]<br>
 -->KEY&nbsp;&nbsp;&nbsp;VALUE 1-1<br>
s:11:"target";&nbsp;&nbsp;&nbsp;a:1:{ ##  ARRAY 2 [2 ELEMENTS]<br><br>
 -->KEY&nbsp;&nbsp;&nbsp;VALUE 1-2 <br>
   i:0;&nbsp;&nbsp;&nbsp;a:1:{    ##  ARRAY 3 [2 ELEMENTS]<br><br>
 -->KEY&nbsp;&nbsp;&nbsp;VALUE 2-1 <br>
   i:1;&nbsp;&nbsp;&nbsp;a:3:{ ##  ARRAY 3 [4 ELEMENTS]<br><br>
 -->KEY&nbsp;&nbsp;&nbsp;VALUE 3-1 <br>
s:5:"param";&nbsp;&nbsp;&nbsp;s:13:"page_selected";<br><br>
 -->KEY&nbsp;&nbsp;&nbsp;VALUE 3-2 <br>
s:8:"operator";&nbsp;&nbsp;&nbsp;s:2:"==";<br><br>
 -->KEY&nbsp;&nbsp;&nbsp;VALUE 3-3 <br>
s:5:"value";&nbsp;&nbsp;&nbsp;a:5:{ ##  ARRAY 4 [6 ELEMENTS]<br><br>
 -->KEY&nbsp;&nbsp;&nbsp;VALUE 4-1 <br>
i:3001;&nbsp;&nbsp;&nbsp;s:13:"Service Areas";<br><br>
 -->KEY&nbsp;&nbsp;&nbsp;VALUE 4-2 <br>
i:1098;&nbsp;&nbsp;&nbsp;s:19:"Water Slide Rentals";<br><br>
 -->KEY&nbsp;&nbsp;&nbsp;VALUE 4-3 <br>
i:672;&nbsp;&nbsp;&nbsp;s:15:"Chairs & Tables";<br><br>
 -->KEY&nbsp;&nbsp;&nbsp;VALUE 4-4 <br>
i:205;&nbsp;&nbsp;&nbsp;s:4:"Home";<br><br>
 -->KEY&nbsp;&nbsp;&nbsp;VALUE 4-5 <br>
i:1401;&nbsp;&nbsp;&nbsp;s:29:"Bounce House Rental Armada MI";<br><br>

} <!-- ENDS ARRAY 5 --><br>
} <!-- ENDS ARRAY 4 --><br>
} <!-- ENDS ARRAY 3 --><br>
} <!-- ENDS ARRAY 2 --><br>
s:15:"sgpb-conditions";N;}  <!-- ENDS ARRAY 1 --><br>

^^^^^^^^^^^^^^^^^^^^^^^^^^

NOT SURE HOW THIS TIES IN

my question is about First issue I am having is a complete understanding of the array. Not sure how the last values tie into an array. Also, an Array is zero based correct?

Here is the code I have created so far to add the array, which is not creating the array correctly.

"<?php<br>
$poddata = Array(<br>
'sgpb-target',<br>
Array (<br>
    1 => Array(<br>
'param' => 'page_selected',<br>
'operator' => '==',<br>
'value' => Array(<br>
                3001 => 'Service Areas',<br>
                1098 => 'Water Slide Rentals',<br>
                672 => 'Chairs & Tables',<br>
                1401 => 'Bounce House Rental Armada MI',<br>
                676 => 'Mobile Gaming Trucks'<br>
                ))));<br>
<br>
update_post_meta(6668, 'poddata', $poddata);<br>
?>"  

Thanks for any help

Share Improve this question edited Feb 27, 2019 at 12:55 Rob Guay asked Feb 27, 2019 at 4:14 Rob GuayRob Guay 32 bronze badges 2
  • Why does your last block of code have <br> tags in it? – Jacob Peattie Commented Feb 27, 2019 at 10:50
  • Bad post editing, I needed to wrap it in [code][/code] tags, and not use html tags to format the post – Rob Guay Commented Feb 27, 2019 at 12:58
Add a comment  | 

1 Answer 1

Reset to default 0

That original value is a serialised array. If you want to see the original array you can use the unserialize() function, or a site like https://www.unserialize. The problem is that this isn't working for your Array, because the serialised value is invalid.

The problem is here:

s:11:"target"

"Target" is 6 letters, so this needs to be:

s:6:"target"

This wouldn't happen if you were properly serialising and unserialising in PHP, but it's an easy mistake to make if you're trying to manually edit the data. Generally it's a bad idea to try and edit serialised data by hand.

Anyway, I assume that you want to insert a valid array, so when you fix that issue and then unserialise it, it looks like this:

array(
    'target' => array(
        0 => array (
            1 => array(
                'param'    => 'page_selected',
                'operator' => '==',
                'value'    => array(
                    3001 => 'Service Areas',
                    1098 => 'Water Slide Rentals',
                    672  => 'Chairs & Tables',
                    205  => 'Home',
                    1401 => 'Bounce House Rental Armada MI',
                ),
            ),
        ),
    ),
    'sgpb-conditions' => NULL,
)

Articles related to this article

Post a comment

comment list (0)

  1. No comments so far