php - include result array inside good language -
i trie include array result inside id language. problem result in double.
$n = sizeof($_post['user_question']); // 3 questions $m = sizeof($languages); // 2 language ($i=0; $i<$n; $i++) { ($j=0; $j<$m; $j++) { $language_id = $languages[$m]['id']+1; if (!is_null($_post['user_question'][$i + $j * $n]) ) { $empty_array = (bool)array_filter($_post['user_question'][$i + $j * $n], create_function('$a','return preg_match("#\s#", $a);')); if ($empty_array == true) { $toto[] = $_post['user_question'][$i + $j * $n]; } } } }
the result var_dump($toto);
array(6) { [0]=> array(1){ [1]=> string(9) "test_en_1" } [1]=> array(1) { [1]=> string(9) "test_en_1" } [2]=> array(1) { [1]=> string(9) "test_en_1" } [3]=> array(1) { [2]=> string(9) "test_fr_1" } [4]=> array(1) { [2]=> string(9) "test_fr_2" } [5]=> array(1) { [2]=> string(9) "test_fr_3" } }
in result : [1]=> string(9) "test_en_1"
[1]
language
if that, have result in double.
how write correctly element below have element save in language ? problem result of array, have in first 3 language_id = 1 , 3 language_id = 2
the loop case does'nt work.
for ($i=0, $n=sizeof($languages); $i<$n; $i++) { $language_id = $languages[$i]['id']; foreach ($toto $key => $value) { $result_value = $value; $sql_data_array = ['user_question ' => $result_value]; $insert_sql_data = ['id' => (int)$_get['pid'], 'language_id' => (int)$language_id ]; $sql_data_array = array_merge($sql_data_array, $insert_sql_data); var_dump($sql_data_array); var_dump('<br>'); } }
the result :
array(3) { ["user_question "]=> array(1) { [1]=> string(9) "test_en_1" } ["id"]=> int(99) ["language_id"]=> int(1) } string(4) " " array(3) { ["user_question "]=> array(1) { [1]=> string(9) "test_en_1" } ["id"]=> int(99) ["language_id"]=> int(1) } string(4) " " array(3) { ["user_question "]=> array(1) { [1]=> string(9) "test_en_1" } ["id"]=> int(99) ["language_id"]=> int(1) } string(4) " " array(3) { ["user_question "]=> array(1) { [2]=> string(9) "test_fr_1" } ["id"]=> int(99) ["language_id"]=> int(1) } string(4) " " array(3) { ["user_question "]=> array(1) { [2]=> string(9) "test_fr_2" } ["id"]=> int(99) ["language_id"]=> int(1) } string(4) " " array(3) { ["user_question "]=> array(1) { [2]=> string(9) "test_fr_3" } ["id"]=> int(99) ["language_id"]=> int(1) } string(4) " " array(3) { ["user_question "]=> array(1) { [1]=> string(9) "test_en_1" } ["id"]=> int(99) ["language_id"]=> int(2) } string(4) " " array(3) { ["user_question "]=> array(1) { [1]=> string(9) "test_en_1" } ["id"]=> int(99) ["language_id"]=> int(2) } string(4) " " array(3) { ["user_question "]=> array(1) { [1]=> string(9) "test_en_1" } ["id"]=> int(99) ["language_id"]=> int(2) } string(4) " " array(3) { ["user_question "]=> array(1) { [2]=> string(9) "test_fr_1" } ["id"]=> int(99) ["language_id"]=> int(2) } string(4) " " array(3) { ["user_question "]=> array(1) { [2]=> string(9) "test_fr_2" } ["id"]=> int(99) ["language_id"]=> int(2) } string(4) " " array(3) { ["user_question "]=> array(1) { [2]=> string(9) "test_fr_3" } ["id"]=> int(99) ["language_id"]=> int(2) } string(4) "
thank you
Comments
Post a Comment