How to put variable in array, wp_insert_post?

You have to convert the $get_value variable in the simple array and then you have to convert in the associative array after that merge both array into one then you can create or update the post through the wp_insert_post() function. you can achieve this by the following code.

if ($get_value) {
    // change the string structure for converting into the array.
    $get_value = "post_content,$postpost->post_content,post_excerpt,$postpost->post_excerpt,post_name,$postpost->post_name,post_title,$postpost->post_title";
} else {
    $get_value="";
}
$args = array(
    'comment_status' => $postpost->comment_status,
    'ping_status' => $postpost->ping_status,
    'post_parent' => $postpost->post_parent,
    'post_passworks' => $postpost->post_password,
    'post_status' => 'publish',
    'post_type' => 'post',
    'to_ping' => $postpost->to_ping,
    'menu_order' => $postpost->menu_order,
);

// converting the string to array.
$string_to_array = explode(',', $get_value);

// converting the simple array to associative array.
function simple_array_to_associative_array($simple_array) {
    $new_array = [];
    $i = 0;
    $last_element = end($simple_array);
    foreach ($simple_array as $index => $value) {
        if($i % 2 == 0 && $last_element == $value) {
            $new_array[$value] = '';
        } elseif($i % 2 == 0) {
            $new_array[$value] = $simple_array[$index + 1];
        }
        $i++;
    }
    return $new_array;
}

$converted_array = simple_array_to_associative_array($string_to_array);

// merge the both array.
$final_args = $args + $converted_array;

$new_post_id = wp_insert_post($final_args);

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)