View difference between Paste ID: sBiCDLhz and htz8AbWQ
SHOW: | | - or go back to the newest paste.
1
Instructions
2-
function one($table,$column,$source_value,$counter="",$arr_where=array(),$extension="")
2+
------------
3
4
- Go through this function line by line, and explain what the code does on each line
5
- Are there any mistakes that need correcting?
6-
      $attempted_new_name = $source_value.$extension;
6+
- What does the function do overall?
7
- What use case do you think this function serves? What's the business logic behind needing this function?
8
- Given your understanding of the function, what potential outputs do you expect from calling:  one("table_name", "column_name, "John")
9
10
<?php
11
function check_name($table, $column, $source_value, $counter = "", $arr_where = array(), $file_extension)
12
{
13
   if($counter == "")
14
   {
15
      $attempted_new_name = $source_value.$file_extension;
16
   }
17
   else
18
   {
19
      $attempted_new_name = $source_value."-".$counter.$extension;
20
   }
21
	
22
	$where = "";
23
	if(count($arr_where) > 0)
24
	{
25
		$where = " AND ".implode(" AND ",$arr_where);
26
	}
27
28-
      if($counter == "")
28+
29
30
   $result = mysqli_query_error_logged($sql);
31
   if(mysqli_num_rows($result) == 0)
32
   {
33
      return $attempted_new_name;
34
   }
35
   else
36-
      return one($table,$column,$source_value,$counter,$arr_where,$extension);
36+
37
      if($counter = "")
38-
}
38+
39
         $counter = 2;
40
      }
41
      else
42-
function two($a, $b)
42+
43
         $counter++;
44-
	return $b == 0 ? 0 : $a/$b;
44+
45-
}
45+
      return one($table, $column, $source_value, $counter, $arr_where, $file_extension);
46-
?>
46+
47
}