Subarrays in arrays
<p>my programm  reads files, and puts a words just one time into new file - it's like vocabulary. 
But I need to create new array or document where exist word - name_of_doc_where_it_wos_found. So it can be "Smile" - "doc1.txt, doc2.txt,...".</p>

<p>Please, help me...</p>

<pre><code>&lt;? 
function clear_file($file_name) { 
  $chrs = array (chr(33), chr(34), chr(35), chr(36), chr(37), chr(38), chr(39), chr(40), chr(41), chr(42), chr(43), chr(44), chr(45), chr(46), chr(47), chr(48), chr(49), chr(50), chr(51), chr(52), chr(53), chr(54), chr(55), chr(56), chr(57), chr(58), chr(59), chr(60), chr(61), chr(62), chr(63), chr(64), chr(91), chr(92), chr(93), chr(94), chr(95), chr(96), chr(123), chr(124), chr(125), chr(126)); 
  $read_file = file_get_contents($file_name, true); 
  $str=str_replace($chrs,' ',$read_file); 
  file_put_contents($file_name, $str); 
} 
?&gt;  

&lt;?php

// read voc
$voc_file = file_get_contents('voc.txt', true);
$voc_array = explode(',',$voc_file);

//read files
$file_pathes = array('1.txt','2.txt');

echo 'Wait... I am scanning... ';
for($k = 0; $k&lt;count($file_pathes); $k++){
    $file_path = $file_pathes[$k];
    //clear incoming files from characters
    clear_file($file_path);

    $file = file_get_contents($file_path, true);
    //read File into a string
        if($file){
            // here we string deviding into a words and put them into array
            $words = explode(' ',$file);
            if($words){
                //compare
                for($i = 0; $i&lt;count($words); $i++){
                    $word = $words[$i];

                    if(in_array($word, $voc_array) == 0){
                        array_push($voc_array,$word);
                        }
                }   
            }else{
                //echo 'empty file at path: ' + $file_path;
            }
        }else{
            //echo 'can not open a file at: ' + $file_path;
        }
}

$output = implode(chr(44),$voc_array);
file_put_contents('voc.txt',$output);
?&gt;
</code></pre>


