php - Looping through letters not working -
i have function, loops on excel columns. working yesterday, having issues. function returning false
according var_dump()
isn't entering loop (i have echoed out "here" within loop , nothing echoed). why isn't working?
$max_col
return correct maximum column
function get_col(phpexcel $excel, $search, $row = 5, $col = "a"){ $max_col = (string)$excel->getactivesheet()->gethighestcolumn(); // returns bh for($i = (string)$col; $i <= $max_col; $i++){ $val = trim($excel->getactivesheet()->getcell("{$i}{$row}")->getvalue()); $search = preg_quote($search); if(preg_match("/$search/isu", $val)){ return "$i"; } } return false; }
here how calling function:
$col = get_col($excel, $sku, 5, "q"); var_dump($col);
using <=
comparison strings cause problems because it's alphabetic comparison, , alphabetically "c" > "bh" adjust initial value of $max_col 1 column beyond max want check, , use !==
comparison
function get_col(phpexcel $excel, $search, $row = 5, $col = "a"){ $max_col = $excel->getactivesheet()->gethighestcolumn(); // returns bh $max_col++; for($i = $col; $i !== $max_col; $i++){ $val = trim($excel->getactivesheet()->getcell("{$i}{$row}")->getvalue()); $search = preg_quote($search); if(preg_match("/$search/isu", $val)){ return "$i"; } } return false; }
Comments
Post a Comment