## String is palindrome or not

 Code Block
`<?php\$origing_str = "khan";\$opesite_str="";\$leng = strlen(\$origing_str);\$str_array=str_split(\$origing_str);for(\$i=\$leng-1;\$i>=0;\$i--){    \$opesite_str.= \$str_array[\$i];}if(\$origing_str==\$opesite_str){	echo 'string is palindrome';}else{	echo 'string is not palindrome';}?>`

## Find the opposite in PHP

 Code Block
`<?php\$origing_str = 1234;\$origing_str.="";\$opesite_str="";\$leng = strlen(\$origing_str);\$str_array=str_split(\$origing_str);for(\$i=\$leng-1;\$i>=0;\$i--){	\$opesite_str.= \$str_array[\$i];}echo "Opposite Number: ".(int)\$opesite_str; ?>`

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

## Multiple Way to check no is odd or even

1. With Modulator
 Code Block
`<?php\$num = 14;if(\$num%2==0) {	echo 'The number is even.';} else {	echo 'The number is odd.';}?>`

2. With Bitwise Operator

 Code Block
`<?php\$num = 14;if(\$num&1) {	echo 'The number is odd.';} else {	echo 'The number is even.';}?>`