通过元数据键和线条获取用户

时间:2019-03-21 作者:NewBle

我已经创建了自定义用户元,但这是一个数组,我只能通过键调用其中一个,就像我只想获取一样course_id = 22 列表
这是我的用户元数组

 [certifications] => Array
        (
            [0] => a:9:{s:9:"course_id";a:2:{i:0;s:0:"";i:1;s:2:"19";}s:11:"course_name";a:2:{i:0;s:0:"";i:1;s:18:"Advanced Freediver";}s:6:"course";a:2:{i:0;s:0:"";i:1;s:2:"19";}s:4:"date";a:2:{i:0;s:0:"";i:1;s:10:"05/03/2019";}s:10:"instructor";a:2:{i:0;s:0:"";i:1;s:11:"Camila Amor";}s:6:"school";a:2:{i:0;s:0:"";i:1;s:24:"Apnea Total Headquarters";}s:11:"pdf_card_id";a:2:{i:0;s:0:"";i:1;s:2:"19";}s:7:"pdf_dip";a:2:{i:0;s:0:"";i:1;s:2:"19";}s:11:"last_update";s:10:"21-03-2019";}
            [1] => a:9:{s:9:"course_id";a:2:{i:0;s:0:"";i:1;s:2:"22";}s:11:"course_name";a:2:{i:0;s:0:"";i:1;s:16:"Master Freediver";}s:6:"course";a:2:{i:0;s:0:"";i:1;s:2:"22";}s:4:"date";a:2:{i:0;s:0:"";i:1;s:10:"08/03/2019";}s:10:"instructor";a:2:{i:0;s:0:"";i:1;s:14:"Andres Alegria";}s:6:"school";a:2:{i:0;s:0:"";i:1;s:17:"Vertical Dreamers";}s:11:"pdf_card_id";a:2:{i:0;s:0:"";i:1;s:2:"22";}s:7:"pdf_dip";a:2:{i:0;s:0:"";i:1;s:2:"22";}s:11:"last_update";s:10:"21-03-2019";}
        ) 

1 个回复
SO网友:NewBle

这就是我的存储数据函数如何用于此元组并获取数据

stored

$certification = array(
        \'course_id\' => $certificate_id,
        \'course\' => $certificate,
        \'date\' => $date,
        \'instructor\' => $certifying_instructor,
        \'school\' => $school,
        \'last_update\' => date(\'d-m-Y\'),
    );

    add_user_meta( $user_ids, \'certifications\',  $certification );

and this get data

$users_detail = get_user_meta($user_id);
$certificates = $users_detail[\'certifications\'];

$n_course_id = array();

foreach ($certificates as $value) {
   $course = unserialize($value);
   $course_id = $course[\'course_id\'];

   foreach ($course_id as $courses) {
     array_push($n_course_id, $courses);
   }

}
通过此函数,我可以获取所有列表,但我只想获取其中一个