how to get output from a loop which is inside a function in php? : guys i'm scraching my head for hours over this problem. As, i'm basically trying to fetch values from a loop inside a function to pass it to another foreach loop to get the desired results.And it is not working as i intend to. pl,point me in the right direction.
here is the code:

          function ff($s) {
        
    $project="";
    foreach ($s as $i=> $r ){
      
        $r["friend_one"] == $_SESSION['uname'] ? $friends[]= $r["friend_two"] : $friends[] = $r["friend_one"]; 
        
        $friend=$friends[$i];
       $totalids=$project->totalids($_SESSION['uname'],$friend);
       }
       return $totalids;
    }
    $totalid=  ff($f);
    print_r($totalid);
           
       
       
       foreach ($totalid as $v){
         
        $id=$v['user_id'];
    //other logic to get desired results   
    }