Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/wordpress/11.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 我可以将两个数组解析为一个函数吗?_Php_Wordpress - Fatal编程技术网

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

Php 我可以将两个数组解析为一个函数吗?,php,wordpress,Php,Wordpress,我有以下方法,它适用于第一个数组,但不适用于第二个数组。如何将两者结合使用并使用一次sendinblue\u runner($data) // Fire the function to add to the imp_customer_log table $data = array( 'id' => '', 'customer_id' => $data['user_

我有以下方法,它适用于第一个数组,但不适用于第二个数组。如何将两者结合使用并使用一次
sendinblue\u 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 );
}

您可以使用
array\u merge
功能

sendinblue_runner(array_merge($first_array, $second_array));

通过添加一个额外的数组来解决:

$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');

您可以使用合并这两个arrays@ReynierPM我尝试了
array\u merge
,但它只是从文档中输出第二个数组:“如果输入数组具有相同的字符串键,则该键的后一个值将覆盖前一个。”这就是为什么。好吧,你必须更好地解释你想要实现什么,因为你发布的信息不清楚。另一方面,您正在使用第二个数组定义覆盖
$data
值,这意味着您已经在所有地方定义了
$data
,正如我所说的,请更清楚地了解您想要实现的目标,以便我们能够帮助您更好地添加到上述内容,您应该从第二个块中获得未定义的索引通知,因为在第一个块之后没有
$data['user\u id']
$data['account\u last\u name']
。确保在开发过程中一直处于打开状态。这会有什么帮助?它们有相同的键,所以它只会替换它们,而不会以任何有用的方式组合它们。