Schlo_50 Posted June 16, 2008 Share Posted June 16, 2008 Hi there, I have a short script and part of it uses a series of if statements, but I am wondering if there is any way to condense the section to make it shorter, or if there is a more efficient/timesaving way to write what I have written? $canid = trim($data[$key][20]); $name = trim($data[$key][0]); $number = str_replace(' ', '', $data[$key][9]); $numberb = str_replace(' ', '', $data[$key][10]); $numberc = str_replace(' ', '', $data[$key][11]); $numberd = str_replace(' ', '', $data[$key][2]); $searchb = str_replace(' ', '', $_POST['c']); if (preg_match("/^$searchb/i", $number)) { print "<img src=\"images/match.gif\" /> <a href=\"?id=operate&action=View_Candidate&cid=".$canid."\">".$name."</a> - ".$number."<br />"; } if (preg_match("/^$searchb/i", $numberb)) { print "<img src=\"images/match.gif\" /> <a href=\"?id=operate&action=View_Candidate&cid=".$canid."\">".$name."</a> - ".$numberb."<br />"; } if (preg_match("/^$searchb/i", $numberc)) { print "<img src=\"images/match.gif\" /> <a href=\"?id=operate&action=View_Candidate&cid=".$canid."\">".$name."</a> - ".$numberc."<br />"; } if (preg_match("/^$searchb/i", $numberd)) { print "<img src=\"images/match.gif\" /> <a href=\"?id=operate&action=View_Candidate&cid=".$canid."\">".$name."</a> - ".$numberd."<br />"; } Thanks in advance for any suggestions! Link to comment https://forums.phpfreaks.com/topic/110389-condensing-code/ Share on other sites More sharing options...
shane07 Posted June 16, 2008 Share Posted June 16, 2008 you can replace the variables-number, numberb, numberc, numberd by an array, say number[$i] and using for-loop you can shorten the code Link to comment https://forums.phpfreaks.com/topic/110389-condensing-code/#findComment-566386 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.