Hi I'm trying to remove the results of one array from another and store the result as a comma seperated list of strings.
This is the code I have so far:
function bpdev_include_users(){
//list of users to exclude
global $wpdb;
$frndsof = array();
$frnds = array();
$result = array();
$friendsid = array();
$currentuser_id = get_current_user_id();
echo $currentuser_id;
?><br />
<?php
$sql= "SELECT friend_user_id FROM wp_bp_friends WHERE initiator_user_id='".$currentuser_id."' AND is_confirmed = 1";
$friendsid = $wpdb->get_results($sql);
print_r($friendsid);
?><br />
<?php
$myexcluded_users=array();
foreach($friendsid as $oneitem){
$myexcluded_users[]=$oneitem->friend_user_id;
}
$excluded_user =implode(", ",$myexcluded_users);
echo $excluded_user;
?><br />
<?php
foreach ( $friendsid as $row )
{
$sql1= "SELECT friend_user_id FROM wp_bp_friends WHERE initiator_user_id='".$row->friend_user_id."' AND is_confirmed = 1";
$ffid = $wpdb->get_results($sql1);
print_r($ffid);
?><br />
<?php
}
More code (sorry weird formatting issues...)
$my_users = array();foreach($ffid as $oneitem){
$my_users[]=$oneitem->friend_user_id;
}
$my_user =implode(", ",$my_users);
echo $my_user;
$sql2= "SELECT user_id FROM wp_bp_xprofile_data";
$users = $wpdb->get_results($sql2);
$result = array_merge($friendsid, $ffid);
//$excluded_user = array_diff($users , $result); //comma separated ids of users whom you want to exclude
}
bpdev_include_users();
What I'm trying to end up with is
$excluded_user = 1, 2, 3, 4;
Currently I'm getting an error at the array_diff stage: Object of class stdClass could not be converted to string
This is the output from the above code
1
Array ( [0] => stdClass Object ( [friend_user_id] => 54 ) [1] => stdClass Object ( [friend_user_id] => 48 ) [2] => stdClass Object ( [friend_user_id] => 61 ) )
54, 48, 61
Array ( [0] => stdClass Object ( [friend_user_id] => 62 ) [1] => stdClass Object ( [friend_user_id] => 51 ) [2] => stdClass Object ( [friend_user_id] => 60 ) [3] => stdClass Object ( [friend_user_id] => 65 ) [4] => stdClass Object ( [friend_user_id] => 56 ) ) Array ( [0] => stdClass Object ( [friend_user_id] => 43 ) [1] => stdClass Object ( [friend_user_id] => 50 ) [2] => stdClass Object ( [friend_user_id] => 64 ) [3] => stdClass Object ( [friend_user_id] => 45 ) [4] => stdClass Object ( [friend_user_id] => 44 ) ) Array ( [0] => stdClass Object ( [friend_user_id] => 57 ) )
57
Thanks in advance for any help!