1
Hello, I’m making a PHP code that picks up a CSV file and am separating the file by "column" States. I want to make a matrix separating the states that repeat as follows:
array(array('SP',array('info1','info2','info3'),array('info1','info2','info3')),
array('RJ',array('info1','info2','info3')),
array('PE',array('info1','info2','info3'),array('info1','info2','info3'))
)
In the code below the IF function should be checking if the acronym has already been inserted in the array. (But for some reason it always results in false). In the code that is run, only Else enters and if always results in false. When the repetition of an acronym occurs, the array(info1,info2,info3) should be inserted in the index from where the repetition of the acronym occurred. As an example above, where in PE and SP two repetitions will occur and RJ only one.
<?php
$exp = file ('CSVs/exp2019_copy.csv');
function processarDados(){
global $exp;
$tabelas = array();
$linha = array();
foreach($exp as $l){
$linha = explode(";",$l); //$linha armazena cada valor da linha como array.
if(array_search($linha[5],$tabelas)!=false){
$tabelas[array_search($linha[5],$tabelas)][] = array($linha[1],$linha[2],$linha[10]);
}
else{
$tabelas[] = array($linha[5],array($linha[1],$linha[2],$linha[10]));
}
} print_r($tabelas);
}
processarDados();
?>
In logic if(array_search($linha[5],$tabelas)!=false)
where in $linha[5]
if you have the string acronym and $tabelas
is the array that should receive Acronym and arrays with 3 information.