2017-12-06 5 views
0

값 :

[0] => var1 
[1] => var2 
[2] => var3 
[3] => ... 

그리고 각각의 값이 존재하는지 확인해야합니다. 더 효율적인 방법이 있습니까

if (in_array('var1', $header) && in_array('var2', $header)... 

CSV 파일 가져 오기에서 열의 일부로 검사 할 15 가지가 있습니다.

감사

+0

은 그냥'foreach' 대신'체인 &&'의 사용합니다. – Andrew

+0

'var1'과'var2'는 문자열입니까? –

답변

0

나는 이런 식으로했다 :

$intersect = array_intersect($expectedCSVHeader, $headerRow->toArray()); 

if (count($intersect) != count($expectedCSVHeader)) { 
    throw new Exception('Column names missing from template. Please repair the CSV file and upload it again'); 
}