I have multiple files that I am trying to consolidate into 1 single file. Each file has something similar to this:
var nr = ['1.02.3.1','1.02.3.4'];
var p = [{"ip":"1.02.3.1","parents":["1.02.3.0","1.1.2.2"},{"ip":"1.04.1.1","parents":["1.1.30.0","1.15.2.2"}];
Keep in mind, I am trying to parsing the information as text for now.
Different files have different IPs, (IPs being the values within the lists. I consolidate 2 files at a time. For the nr array, it's easy. All I did was strip the unnecessary data to leave me with '1.02.3.1','1.02.3.4' then I exploded the string into an array. I merge the array with the other file's array, take out duplicates, implode the data, add the "var nr =[" and "];"
I am having trouble with the next part. I want to cross check "p" with "nr". With the consolidated "nr" array. If any of the values of "nr" match the ip of "p, then save write the ip to a new array called "nrp" and save the list of parents from that ip to the consolidated "p" array. Also, I want to delete the ip and parent ips that are not listed by "nr".
For example, I will represent ip as letters
File A:
var nr = ['A','B','C'];
var p = [{"ip":"A","parents":["J","K","L"]},{"ip":"B","parents":["J","K","L"]},{"ip":"C","parents":["K","L","M"]} ];
File B:
var nr = ['A','C','D'];
var p = [{"ip":"A","parents":["J","K","L"]},{"ip":"D","parents":["N","O","P"]},{"ip":"C","parents":["K","L","M"]} ];
File consolidate:
var nr = ['A','B','C','D'];
var p = [{"ip":"A","parents":["J","K","L"]},{"ip":"B","parents":["J","K","L"]},{"ip":"D","parents":["N","O","P"]},{"ip":"C","parents":["K","L","M"]}];
var nrp = ['J','K','L','N','O','P','M'];
My approach so far: This is after I have the data in arrays.
$consolidatedNR = ['A','B','C','D'];
$consolidatedP = [{"ip":"A","parents":["J","K","L"]},{"ip":"B","parents":["J","K","L"]},{"ip":"D","parents":["N","O","P"]},{"ip":"C","parents":["K","L","M"]}];
foreach($consolidatedP as $key5 => &$string5){
foreach($consolidatedNR as $key2 => &$ip){
if($string5 contains "'ip':$ip"){
array_push($content4, $ip);
}
else{
unset($consolidatedP[$key5]);
}
}
}