Fill In An Associative Array With A Foreach From An Other Array Php

Hi there,

I just need to fill in an empty array : $file_info['threads']['selected_threads'] with data from another array, the result should look like this :

1. Array
(
    [19] => Array
        (
            [enable] => Y
        )
[47] => Array
    (
        [enable] => Y
    )

[48] => Array
    (
        [enable] => Y
    )

[52] => Array
    (
        [enable] => Y
    )

[43] => Array
    (
        [enable] => Y
    )

)

This is my attempt to do so, but I still get an empty array for some reason:

} else {
        //fn_set_notification('E', __('error'), __('ss_order_threads_no_selected_threads'));
        $threads = db_get_array("SELECT * FROM ?:ss_order_threads_links WHERE order_id = ?i", $order_info['order_id']);
        fn_print_r($threads);
        foreach ($threads as $key => $thread) {
        $file_info['threads']['selected_threads'] = array();
        foreach ($file_info['threads']['selected_threads'] as $key =>$selected){
            $array[$key]['id'] = $selected->$thread['thread_id'];
            $res = array("enable" => "Y");
            $array[$key]['value'] = $selected-> $res;
        }
     }
     print('Check 
'); fn_print_r($file_info['threads']['selected_threads']); } } // end function fn_ss_order_threads_generate_file

Would be great if someone can give me a tip here.

Thanks.

Please try to replace foreach with the following code

        foreach ($file_info['threads']['selected_threads'] as $key =>$selected){
            $file_info['threads']['selected_threads'][$selected['thread_id']] = [
                'enable' => 'Y'
            ];
        }

Please try to replace foreach with the following code

        foreach ($file_info['threads']['selected_threads'] as $key =>$selected){
            $file_info['threads']['selected_threads'][$selected['thread_id']] = [
                'enable' => 'Y'
            ];
        }


Thanks for the suggestion, we just need to change $file_info['threads']['selected_threads'] with $threads.

Works like a charm now.

 $threads = db_get_array("SELECT * FROM ?:ss_order_threads_links WHERE order_id = ?i", $order_info['order_id']);
        $file_info['threads']['selected_threads'] = array();
        foreach ($threads as $key => $thread){
            $file_info['threads']['selected_threads'][$thread['thread_id']] = [
                'enable' => 'Y'
            ];
        }
     print('Check 
'); fn_print_r($file_info['threads']['selected_threads']);

Thanks for the suggestion, we just need to change $file_info['threads']['selected_threads'] with $threads.

Yes, you are right.