您可以使用implode
连接数组元素的函数:
$get_the_following_users = get_user_meta($current_user->ID, \'following_users\', true);
$meta_qssuery = \'\'; //initialise to an empty string
foreach ( $get_the_following_users as $following_user ) {
$following_user = get_user_meta($following_user, \'following_users\', true);
if(!empty($following_user)) { //check if any data was returned
$meta_qssuery .= implode(\', \', $following_user).\', \';
}
}
echo $meta_qssuery;
这将在字符串的末尾留下一个额外的“,”。可以在循环结束后删除,也可以修改循环:
$get_the_following_users = get_user_meta($current_user->ID, \'following_users\', true);
$get_the_following_users_2 = array();
foreach ( $get_the_following_users as $following_user ) {
$following_user = get_user_meta($following_user, \'following_users\', true);
if(!empty($following_user)) { //check if any data was returned
$get_the_following_users_2[] = implode(\', \', $following_user);
}
}
$meta_qssuery = implode(\', \', $get_the_following_users_2);
echo $meta_qssuery;