我可以将两个数组解析为一个函数吗?

我有以下适用于第一个数组但不适用于第二个数组的内容。如何将两者结合使用sendinblue_runner($data)一次?


    // Fire the function to add to the imp_customer_log table

    $data = array(

        'id'                            => '',

        'customer_id'           => $data['user_id'],

        'event'                     => 'first_name',

        'data'                      => $data['account_first_name'],

        'updated_in_sib'    => '0',

    );

    sendinblue_runner($data);


    // Fire the function to add to the imp_customer_log table

    $data = array(

        'id'                            => '',

        'customer_id'           => $data['user_id'],

        'event'                     => 'last_name',

        'data'                      => $data['account_last_name'],

        'updated_in_sib'    => '0',

    );

    sendinblue_runner($data);

然后我有我的跑步者:


// Runner to grab data from all the functions that affect SiB contact fields

function sendinblue_runner($data) {

  global $wpdb;

  $table = "imp_customer_log";

  $wpdb->insert( $table, $data );

}


鸿蒙传说
浏览 189回答 2
2回答

德玛西亚99

通过添加额外的数组解决:$data_in = array(    array(        'id'                            => '',        'customer_id'           => $data['user_id'],        'event'                     => 'FIRSTNAME',        'data'                      => $data['account_first_name'],        'updated_in_sib'    => '0',    ),    array(        'id'                            => '',        'customer_id'           => $data['user_id'],        'event'                     => 'LASTNAME',        'data'                      => $data['account_last_name'],        'updated_in_sib'    => '0',    ));sendinblue_runner($data_in);并循环遍历每个数组:function sendinblue_runner($data_in) {  global $wpdb;  $table = "imp_customer_log";  foreach( $data_in as $data ) {    $wpdb->insert( $table, $data);  }}add_shortcode('sib_runner', 'sendinblue_runner');

慕哥6287543

您可以使用该array_merge功能sendinblue_runner(array_merge($first_array, $second_array));
打开App,查看更多内容
随时随地看视频慕课网APP