I'm struggling to pass a value from a recursive function into an array in a different method. I have written my recursive function below.
function get_parent_basket_id($parent_id) {            
    if($parent_id==NULL){
        return false;
    }
    $baskets = $this->Model_cds_clients->clients($parent_id)->result();
    if(count($baskets)==0){
        return false;
    }
    foreach ($baskets as $row) {    
        if($row->parent_id==0){
            return $row->id;
       } else {
           $this->get_parent_basket_id($row->parent_id);
       }    
    } 
}
My Model_cds_clients code is below
function clients ($parent_id) {
    $this->db->select('endpoint, parent_id');
    $this->db->from('cds_clients');
    $this->db->where('parent_id', $parent_id);
    $this->db->where('active', 1);                
    $result = $this->db->get();
    return $result;
}
My table structure for my model looks like below
id - int(11)
name - varchar(255)
endpoint - varchar(64)
active - tinyint(1)
parent_id - int(11)
Below is my function where I need to pass the variable into the client_id under the endpoints array.
public function __construct() {
    parent::__construct();
    $this->load->model('Model_story'); 
    $this->get_parent_basket_id($parent_id);
    $data = array(
        'basket_id' => $this->basketId,
        'story_id' => $this->storyId,
        'payload' => $this->xmlString,                 
        'endpoints' => array(
                           array(
                               'client_id' => XXXX,
                               'endpoint_url' => 'http://www.example.com/consume.php'
                           ), )
    );
    $json_payload = json_encode($data);
Please help.
 
     
     
    