Jump to content

condensing code


Schlo_50

Recommended Posts

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.