0

I am new in wordpress and I confuse how to solve this.

$redeem = array(
  date('Ymd'),
  $_POST['value']
);

if ($point && is_array($point)) {
  $n = sizeof($point);
  $point[$n] = $redeem;
   }

  update_user_meta(get_current_user_id(), 'value', $point);
} else {
  update_user_meta(get_current_user_id(), 'value', $redeem );
}

This code work properly, it makes the data in my database become array. The problem is, how can I show the data from my database into my work page ?

a:3:{i:0;s:8:"20160421";i:1;s:3:"222"; 

This is the result of value in my database. I just want to show the value of "222".

Thanks

5
  • this is a serialized odject, so you want to use unserialize() function over that object: php.net/manual/en/function.unserialize.php Commented Apr 21, 2016 at 7:18
  • I dont know if it is my browser or not, but could you give me a reference in english, because it is in russian. Thanks Commented Apr 21, 2016 at 7:22
  • Yes, i've updated my comment with EN link Commented Apr 21, 2016 at 7:26
  • Could some of you give me the example of the code ? I am new and I dont know much about the syntax. Thanks Commented Apr 21, 2016 at 7:34
  • @MarkVullen, checkout my answer below with simple code. Try that and let me know if you need further help. Commented Apr 21, 2016 at 7:36

1 Answer 1

1

In WordPress, when you insert/update array data into user_meta or post_meta table, it will automatically saves data in serialized form, so you have to unserialize those data while fetching.

Below you can find simple conversation for array to serialized data and serialized data to array. You have to pass serialized data into unserialize function to fetch 222 value.

$arr = array("name"=>"milap","language"=>"php","cms"=>"WordPress");
$sd  = serialize($arr);
$res = unserialize($sd);
echo "<pre>";print_r($res);

The output of above code is,

Array
(
    [name] => milap
    [language] => php
    [cms] => WordPress
)
Sign up to request clarification or add additional context in comments.

13 Comments

hey, I try that and I got this as the result: Array ( [0] => 20160421 [1] => 222 [2] => Array ( [0] => 20160421 [1] => 101 ) [3] => Array ( [0] => 20160421 [1] => 100 )
Can you explain how to fetch the 222 value right after this ?
If you have variable $val, Just access element $val[1] to get 222 value from array.
I mean not just accessing the value but also to write it into my work page. I already try to echo it but it doesnt work. I tried: echo $res[1];
I am confused, please write down your output array.
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.