我正在使用PHPExcel
,我有一個叫做$sheetData
的多維數組。我希望能夠搜索字符串D650
。搜索陣列 - PHPExcel
例如,如果字符串D650
在$sheetData[12][E]
我希望它返回[12][E]
。我似乎無法找到PHPExcel的搜索功能。我試過下面的代碼,但我只獲得一個值,我需要所有的值。如果代碼不是解決此問題的最佳方法,請告訴我。由於
function searchForId($id, $array) {
foreach ($array as $key => $val) {
$letter = "A";
for($i = 1; $i<= 26; $i++)
{
if ($val[$letter] === $id) {
return $key;
}
$letter++;
}
}
return null;
}
$id = searchForId('Denter code here650', $sheetData);
echo $id;
注意PHPExcel不提供搜索功能的陣列來搜索,也沒有提供一個發現的數組在工作表函數中,但在您自己的代碼中實現並不困難 –