## 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 )