Jump to content

  • You cannot start a new topic
  • You cannot reply to this topic

Fill In An Associative Array With A Foreach From An Other Array Php Rate Topic   - - - - -

 
  • Bygora
  • Member
  • Members
  • Join Date: 14-Jan 22
  • 33 posts

Posted 21 September 2022 - 01:26 PM #1

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 <br>');
     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. 



 
  • eComLabs
  • CS-Cart Expert
  • Authorized Reseller
  • Join Date: 27-Jan 14
  • 23040 posts

Posted 21 September 2022 - 01:56 PM #2

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'
            ];
        }

GET A FREE QUOTE | CS-Cart Add-ons | CS-Cart Licenses | CS-Cart Development | CS-Cart Design | Server Configuration | UniTheme and YOUPI
CS-Cart                USD 1210     Multi-Vendor              USD 1250    Multi-Vendor PLUS           USD 3100 (2775)
CS-Cart Ultimate  USD 4025     CS-Cart + YOUPI      USD 1459      Multi-Vendor Ultimate       USD 7500 (6000)


 
  • Bygora
  • Member
  • Members
  • Join Date: 14-Jan 22
  • 33 posts

Posted 22 September 2022 - 07:15 AM #3

 

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 <br>');
     fn_print_r($file_info['threads']['selected_threads']);

 



 
  • eComLabs
  • CS-Cart Expert
  • Authorized Reseller
  • Join Date: 27-Jan 14
  • 23040 posts

Posted 22 September 2022 - 01:12 PM #4

 

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

 

Yes, you are right.


GET A FREE QUOTE | CS-Cart Add-ons | CS-Cart Licenses | CS-Cart Development | CS-Cart Design | Server Configuration | UniTheme and YOUPI
CS-Cart                USD 1210     Multi-Vendor              USD 1250    Multi-Vendor PLUS           USD 3100 (2775)
CS-Cart Ultimate  USD 4025     CS-Cart + YOUPI      USD 1459      Multi-Vendor Ultimate       USD 7500 (6000)