//taking number as parameter function convert_digit_to_words($no) { //creating array of word for each digit $words = array('0'=> 'Zero' ,'1'=> 'one' ,'2'=> 'two' ,'3' => 'three','4' => 'four','5' => 'five','6' => 'six','7' => 'seven','8' => 'eight','9' => 'nine','10' => 'ten','11' => 'eleven','12' => 'twelve','13' => 'thirteen','14' => 'fourteen','15' => 'fifteen','16' => 'sixteen','17' => 'seventeen','18' => 'eighteen','19' => 'nineteen','20' => 'twenty','30' => 'thirty','40' => 'forty','50' => 'fifty','60' => 'sixty','70' => 'seventy','80' => 'eighty','90' => 'ninty','100' => 'hundred','1000' => 'thousand','100000' => 'lac','10000000' => 'crore'); //$words = array('0'=> '0' ,'1'=> '1' ,'2'=> '2' ,'3' => '3','4' => '4','5' => '5','6' => '6','7' => '7','8' => '8','9' => '9','10' => '10','11' => '11','12' => '12','13' => '13','14' => '14','15' => '15','16' => '16','17' => '17','18' => '18','19' => '19','20' => '20','30' => '30','40' => '40','50' => '50','60' => '60','70' => '70','80' => '80','90' => '90','100' => '100','1000' => '1000','100000' => '100000','10000000' => '10000000'); //for decimal number taking decimal part $cash=(int)$no; //take number wihout decimal $decpart = $no - $cash; //get decimal part of number $decpart=sprintf("%01.2f",$decpart); //take only two digit after decimal $decpart1=substr($decpart,2,1); //take first digit after decimal $decpart2=substr($decpart,3,1); //take second digit after decimal $decimalstr=''; //if given no. is decimal than preparing string for decimal digit's word if($decpart>0) { $decimalstr.="point ".$numbers[$decpart1]." ".$numbers[$decpart2]; } if($no == 0) return ' '; else { $novalue=''; $highno=$no; $remainno=0; $value=100; $value1=1000; while($no>=100) { if(($value <= $no) &&($no < $value1)) { $novalue=$words["$value"]; $highno = (int)($no/$value); $remainno = $no % $value; break; } $value= $value1; $value1 = $value * 100; } if(array_key_exists("$highno",$words)) //check if $high value is in $words array return $words["$highno"]." ".$novalue." ".convert_digit_to_words($remainno).$decimalstr; //recursion else { $unit=$highno%10; $ten =(int)($highno/10)*10; return $words["$ten"]." ".$words["$unit"]." ".$novalue." ".convert_digit_to_words($remainno ).$decimalstr; //recursion } } }
Number to Word Conversion PHP
function no_to_words($no) { $words = array('0'=> '' ,'1'=> 'one' ,'2'=> 'two' ,'3' => 'three','4' => 'four','5' => 'five','6' => 'six','7' => 'seven','8' => 'eight','9' => 'nine','10' => 'ten','11' => 'eleven','12' => 'twelve','13' => 'thirteen','14' => 'fouteen','15' => 'fifteen','16' => 'sixteen','17' => 'seventeen','18' => 'eighteen','19' => 'nineteen','20' => 'twenty','30' => 'thirty','40' => 'fourty','50' => 'fifty','60' => 'sixty','70' => 'seventy','80' => 'eighty','90' => 'ninty','100' => 'hundred &','1000' => 'thousand','100000' => 'lakh','10000000' => 'crore'); if($no == 0) return ' '; else { $novalue=''; $highno=$no; $remainno=0; $value=100; $value1=1000; while($no>=100) { if(($value <= $no) &&($no < $value1)) { $novalue=$words["$value"]; $highno = (int)($no/$value); $remainno = $no % $value; break; } $value= $value1; $value1 = $value * 100; } if(array_key_exists("$highno",$words)) return $words["$highno"]." ".$novalue." ".no_to_words($remainno); else { $unit=$highno%10; $ten =(int)($highno/10)*10; return $words["$ten"]." ".$words["$unit"]." ".$novalue." ".no_to_words($remainno); } } } echo no_to_words(12345401);
Counting Array Arguments
package com.apryll.package2; public class sample2 { public static void main(String args[]) { sample2 objsample2 = new sample2(); objsample2.argCount(1, 2, 3, 4); } public void argCount(int num1, int num2, int... args) { System.out.println(num1); System.out.println(num2); System.out.println(args.length); } }
OP
1
2
2
Please Note the Last 2 which accounts for the array argument args as num1 and num2 does not account for array arguments
If the Code is like below then it would have been a error
public void argCount(int num1, int num2, int... args)
Creation of Static Array
static final int[] a = { 100,200 }; static final int[] a; static { a=new int[2]; a[0]=100; a[1]=200; }
Looping through Arguments in Function
How to Loop Through Arguments Passed to function
package com.apryll.package2; public class sample2 { public static void main(String args[]) { sample2 objsample2 = new sample2(); objsample2.argCount(1, 2, 3, 4); } public void argCount(int... args) { System.out.println(args.length); } }
Importing Classes and Methods
Sample1.java
package com.apryll.package1; //import static com.apryll.package2.sample2.Funct3; public class Sample1 { public static void main(String[] args) { Sample1 objSample1 = new Sample1(); //sample2 objSample2 = new sample2(); System.out.println(com.apryll.package2.sample2.City); objSample1.Funct2(); //objSample2.Funct4(); //Sample1.Funct1(); } static void Funct1() { System.out.println("I am Static Function 1"); } void Funct2() { System.out.println(Funct3()); System.out.println(City); } }
Sample2.java
package com.apryll.package2; public class sample2 { public static int City = 555; public static String Funct3() { return "Hi there"; } public void Funct4() { System.out.println("Hello There"); } }
1
package com.apryll.package1; import com.apryll.package2.sample2.*; public class Sample1 { public static void main(String[] args) { sample2 objSample2 = new sample2(); } }
The Above Code Does not Work when creating a object for sample2 since in the import statements is sample2.* is given.It should be
import com.apryll.package2.sample2; . . . .
2
While Importing class methods and variables the static will not get imported unless you specify static
import in the import statement
You can Import the Static Methods and Variables in class as below
To Import static methods and Variables
import static com.apryll.package2.sample2.*;
To Import static methods and Variables
import static com.apryll.package2.sample2.*;
To Import static Variable City
import static com.apryll.package2.sample2.City;
To Import static Function getCityName
import static com.apryll.package2.sample2.getCityName;
3
You can directly access static method and Variable declared in some other package in static void main() method as follows
System.out.println(com.apryll.package2.sample2.City); System.out.println(com.apryll.package2.sample2.Funct3());
Retreive records from Procedure which returns different Resultsets
$objConn = setDbConn(); $strSQL = "CALL mp_proc_getHomePageProjNews('Chennai')"; if($objConn->multi_query($strSQL)) { do { $l = 0; /* store first result set */ if ($result = $objConn->use_result()) { while($row = $result->fetch_row()) { $arrTempResult[] = $row; } $arrResult[] = $arrTempResult; unset($arrTempResult); $result->close(); } if($objConn->more_results()) { } } while ($objConn->next_result()); }
Mysql Procedure Taking parameter
DROP PROCEDURE IF EXISTS proc_sample1; CREATE PROCEDURE proc_sample1(IN pFruitId VARCHAR(255)) BEGIN SET @strSQL = 'SELECT fruit_name FROM fruits WHERE fruit_id = ?'; SET @pFruitId = pFruitId; PREPARE stmt FROM @strSQL; EXECUTE stmt USING @pFruitId; DEALLOCATE PREPARE stmt; END
Alternate to Inner Join which prevents repetation of Records
create table fruits(fruit_id int, fruit_name VARCHAR(255)); create table type(fruit_id int, status VARCHAR(255)); INSERT INTO fruits(fruit_id, fruit_name) values(101, 'Apple'), (102, 'Mango'), (103, 'Lemon'), (104, 'Grape'), (105, 'Orange'); INSERT INTO type(fruit_id, status) values(101, 'Edible'), (101, 'Sweet'), (102, 'Edible'), (103, 'Edible'), (103, 'Salty'), (103, 'Sour'), (104, 'Sour');
When i Use Inner Join as Below the Output would be
To prevent the repetition of fruit name the queries are as follows
SELECT f.fruit_id, f.fruit_name FROM fruits f WHERE f.fruit_id in(SELECT DISTINCT fruit_id FROM type); SELECT DISTINCT t.Fruit_id, fruit_name FROM fruits f RIGHT OUTER JOIN type t ON F.Fruit_id = t.Fruit_id; SELECT fruits.* FROM fruits inner join type on type.fruit_id = fruits.fruit_id GROUP BY type.fruit_id;
How to add Compression to php file using Gzip
There are two ways of adding compression to php file
Method 1
Simple add the below line in the php file at the beginning
ob_start( 'ob_gzhandler' );