我想显示JSON编码值的部分值。以下是代码。
<?php global $wpdb; $project_member_details = $wpdb->get_var( $wpdb->prepare( "SELECT project_members FROM wpxa_project_members WHERE project_id = 603" ) ); echo $project_member_details; ?>
我得到以下结果。。。
{"member_image":["21604_1530889966_1408904487.png","21604_1530889966_1590217155.jpg","21604_1530889966_1179667677.png"],"member_name":["Test","Best","Guest"],"member_role":["Test1","Best1","Guest1"],"member_email":["[email protected]","[email protected]","[email protected]"],"member_facebook_id":["Test3","Best3","Guest3"]}
但我只想要这个。。。如何做。。。
{"member_image":["21604_1530889966_1408904487.png","21604_1530889966_1590217155.jpg","21604_1530889966_1179667677.png"]
Plz帮助。。。
最合适的回答,由SO网友:phatskat 整理而成
使用json_decode
:
global $wpdb;
$project_member_details = $wpdb->get_var( $wpdb->prepare( "SELECT project_members FROM wpxa_orocox_project_members WHERE project_id = 603" ) );
$project_member_details = json_decode( $project_member_details, true );
print_r( $project_member_details[\'member_image\'] );
如果您仍然希望输出的结尾是JSON编码的,那么可以执行以下操作:
$member_images = $project_member_details[\'member_image\'];
echo wp_json_encode( [ \'member_image\' => $member_images ] );