## Function Declaration vs Function Expression

You guys several times will have seen the function in two syntax.

#### 1)Function Declaration

 Code Block
`function func_name(arg_1, arg_2,..., arg_n){    .............    ...........}`

#### 2)Function Expression

 Code Block
`var func_name;func_name=function(){    ....................    .............}; `

Here are the differences

• Function expression can’t be called before its definition vs Function declaration can.

## Array Sorting With Single Loop

There is an unsorted array of integers. write the complete program to find the second largest no in the array without using sorting and max functions. You can only iterate(loop) over the array once.

 Code Block
`<?phpecho "<br/>";\$arr=array(12,52,2,35,95,17,37,42);echo "Before Sorting<br/>";print_r(\$arr);\$tot_arr=count(\$arr);for(\$i=0;\$i<\$tot_arr;\$i++){	if((\$i< (\$tot_arr-1)) && \$arr[\$i]>\$arr[\$i+1]){		\$temp=\$arr[\$i];		\$arr[\$i]=\$arr[\$i+1];		\$arr[\$i+1]=\$temp;		\$i=-1;	}}echo "<br/>After Sorting<br/>";print_r(\$arr);?>`

Output:

Before Sorting
Array ( [0] => 12 [1] => 52 [2] => 2 [3] => 35 [4] => 95 [5] => 17 [6] => 37 [7] => 42 )
After Sorting
Array ( [0] => 2 [1] => 12 [2] => 17 [3] => 35 [4] => 37 [5] => 42 [6] => 52 [7] => 95 )

## Find no of time a character used in string using PHP

 Code Block
`function char_in_string(\$string){ \$char_array=str_split(\$string); for(\$i=0;\$i<sizeof(\$char_array);\$i++){   \$no_of_char[\$char_array[\$i]]=0;   for(\$j=0;\$j<sizeof(\$char_array);\$j++){     if(\$char_array[\$i]==\$char_array[\$j])     {       \$no_of_char[\$char_array[\$i]]++;     }   } } return \$no_of_char;}`

Now show its structure using var_dump()

`var_dump(char_in_string("Hello Ahmad Asjad"));`

Its result will look something like this.

```array (size=12)
'H' => int 1
'e' => int 1
'l' => int 2
'o' => int 1
' ' => int 2
'A' => int 2
'h' => int 1
'm' => int 1
'a' => int 2
'd' => int 2
's' => int 1
'j' => int 1```

## HTML Boolean Attributes

The presence of boolean attribute on html element represents it true and absence of boolean attribute on any html element represents it false.

If the attribute is present in any html element, its value must be empty or the name of the attribute in value of attribute like below:

Possible Correct Syntax:

 Code Block
`<tag_name attribute_name="attribute_name"></tag_name><tag_name attribute_name="attribute_name" /><tag_name attribute_name=""></tag_name><tag_name attribute_name="" /><tag_name attribute_name></tag_name><tag_name attribute_name />`

Possible Wrong Syntax:

 Code Block
`<tag_name attribute_name="true"></tag_name><tag_name attribute_name="false"></tag_name><tag_name attribute_name="true" /><tag_name attribute_name="false" />`

The values “true” and “false” are not allowed on boolean attributes. To represent a false value, the attribute has to be omitted altogether.

Here are the some of boolean attribute of HTML elment.

• seamless
• checked
• hidden
• disabled
• required

## Difference between “WHERE” and ”HAVING” clause

where clause can not accept aggregate function like sum, count, etc. whereas having clause can accept the aggregate functions like sum, count, average, etc.

Let’s see it by example.

paid_id emp_id  salary_given salary_month emp_salary_paid 1 1 1000 jan 2 2 1500 jan 3 3 2000 jan 4 1 1200 feb 5 2 1500 feb 6 3 1800 feb

emp_id emp_name emp_detail 1 Sajid 2 John 3 Ahmad

Query:

 Code Block
`SELECT emp_detail.emp_name, emp_salary_paid.salary_month, emp_salary_paid.salary_givenFROM emp_detail, emp_salary_paidWHERE emp_detail.emp_id=emp_salary_paid.emp_id`

will produce result like this one. because no aggregate function is being used here.

emp_name salary_month salary_given
Sajid jan 1000
Sajid feb 1200
John jan 1500
John feb 1500
 Code Block
`SELECT emp_detail.emp_name, SUM(emp_salary_paid.salary_given) AS total_paidFROM emp_detail, emp_salary_paidGROUP BY emp_detail.emp_idWHERE SUM(emp_salary_paid.salary_given) >2000`

This will produce an error, because aggregate function is being used with where clause. To overcome this, we use having clause like this one.

 Code Block
`SELECT emp_detail.emp_name, SUM(emp_salary_paid.salary_given)FROM emp_detail, emp_salary_paidGROUP BY emp_detail.emp_idHAVING SUM(emp_salary_paid.salary_given) > 2000`

This will produce the correct result as follows:

emp_name total_paid
Sajid 9000
John 9000