0

I just added some custom fields for users. So 'api' is one of them.

function abc(){
    $current_user = wp_get_current_user();
    print_r(get_user_meta($current_user->id)['api'][0]);

}

add_action('init', 'abc');

And the result I get is a string:

a:2:{i:0;s:9:"paybphone";i:1;s:3:"ips";}

I don't know how to access "i" value from the PHP code as its string. And I also know its not JSON , so I also can't use 'json_encode()' function. Please help me out ! I am new to Wordpress programming.

  • 1
    Does this answer your question? [How to use php serialize() and unserialize()](https://stackoverflow.com/questions/8641889/how-to-use-php-serialize-and-unserialize) – El_Vanja May 06 '21 at 15:33
  • That's called a serialized string and the linked question explains its handling. – El_Vanja May 06 '21 at 15:33

1 Answers1

1

You can pass your result into the unserialize() function from php, it will return your PHP array that you can easily access after

More info : https://www.php.net/manual/en/function.unserialize.php

Thomas
  • 410
  • 9
  • 14