2017-06-11 3 views
0

Ich habe zwei Arrays wie unten;Benötigen Sie Hilfe zum Mischen von Arrays

$array1 = array(
    'cover.xhtml', 
    'title.xhtml', 
    'copyright.xhtml', 
    'dedication.xhtml', 
    'toc_brief.xhtml', 
    'toc.xhtml', 
    'ch02_1.xhtml', 
    'ch02_2.xhtml', 
    'ch02_3.xhtml', 
    'ch02_4.xhtml', 
    'ch02_5.xhtml', 
    'ch02_6.xhtml', 
    'ch02_7.xhtml', 
    'ch02_8.xhtml', 
    'ch02_9.xhtml', 
    'ch02_10.xhtml' 
); 

$array2 = array(
    '', 
    'title.xhtml', 
    'copyright.xhtml', 
    'dedication.xhtml', 
    'ch02_2.xhtml', 
    'ch02_2#454.xhtml', 
    'ch02_4.xhtml', 
    'ch02_1.xhtml', 
    'ch02_11.xhtml', 
    'ch02_12.xhtml', 
    '' 
); 

Ergebnis sollte sein:

array(
    'cover.xhtml', 
    'title.xhtml', 
    'copyright.xhtml', 
    'dedication.xhtml', 
    'toc_brief.xhtml', 
    'toc.xhtml', 
    'ch02_1.xhtml', 
    'ch02_2.xhtml', 
    'ch02_2#454.xhtml', 
    'ch02_3.xhtml', 
    'ch02_4.xhtml', 
    'ch02_5.xhtml', 
    'ch02_6.xhtml', 
    'ch02_7.xhtml', 
    'ch02_8.xhtml', 
    'ch02_9.xhtml', 
    'ch02_10.xhtml', 
    'ch02_11.xhtml', 
    'ch02_12.xhtml' 
) 

Ich habe versucht, mit: call_user_func_array('array_merge', array_map(null, $array1, $array2)); Das ist nicht das Ergebnis zu produzieren, was ich wie beschrieben erforderlich. Bitte helfen Sie.

Antwort

0

Wenn der Auftrag nicht wirklich wichtig, verwenden:

$array3 = array_values(array_unique(array_filter(array_merge($array1, $array2)))); 

Ausgang:

Array 
(
    [0] => cover.xhtml 
    [1] => title.xhtml 
    [2] => copyright.xhtml 
    [3] => dedication.xhtml 
    [4] => toc_brief.xhtml 
    [5] => toc.xhtml 
    [6] => ch02_1.xhtml 
    [7] => ch02_2.xhtml 
    [8] => ch02_3.xhtml 
    [9] => ch02_4.xhtml 
    [10] => ch02_5.xhtml 
    [11] => ch02_6.xhtml 
    [12] => ch02_7.xhtml 
    [13] => ch02_8.xhtml 
    [14] => ch02_9.xhtml 
    [15] => ch02_10.xhtml 
    [16] => ch02_2#454.xhtml 
    [17] => ch02_11.xhtml 
    [18] => ch02_12.xhtml 
) 

Check it out here. Der Code führt Folgendes aus: fusionieren ->leer entfernen ->Duplikate entfernen ->fix Schlüssel.

+0

Danke für die Antwort. Die Reihenfolge ist wirklich wichtig. Also immer noch versuchen, eine Lösung zu bekommen. – Arghya

+0

@Arghya das wird hart sein, da es nicht wirklich einem logischen Pfad folgt. Es ist keine alphabetische Reihenfolge, es ist nur für den "ch" -Teil bestellt. – FirstOne

+0

hmm Ich verstehe und stimme zu Ich bin seit den letzten 2 Tagen dran. – Arghya

Verwandte Themen