$start = Array(25000, 30000, 40000, 15900, 46000);
$end   = Array(45000, 47000, 60000, 55000, 85000);

$cnt2 = 0;

foreach($start as $val)
{
    $cnt  = 0;

    for($i=0;$i<count($start); $i++)
    {
        if($start[$i] <= $val && $val < $end[$i])           $cnt++;                  if($cnt == count($start))           $start_budget = $val;         elseif($cnt >$cnt2)
        {
     	  $cnt2			= $cnt;
     	  $start_budget = $val;
        } 
    }

    if($cnt2 == 0)
     $cnt2 = $cnt;

}

$cnt2 = 0;

foreach($end as $val)
{
    $cnt = 0;

    for($i=0;$i<count($end); $i++)
    {
      if($start[$i] < $val && $val <= $end[$i])        $cnt++;                if($cnt == count($end))        $end_budget = $val;       elseif($cnt > $cnt2)
      {
      	$cnt2 		= $cnt;
      	$end_budget = $val;
      }

      if($cnt2 == 0)
       $cnt2 = $cnt;      
    }   

}

echo $start_budget;
echo  "<br/>";
echo $end_budget;
Posted in PHP.

I have a Two PHP arrays as Below

Array 1 – Budget Start
$start = Array(25000,30000,35000,15900);

Array 2 – Budget End
$end = Array(40000,50000,60000,55000);

I want to Filter the Budget range which the user is actually looking for.For the above the budget range is 35000 For Budget Start and 40000 for Budget End.

Budget Start 35000 because
25000 <= 35000 < 40000
30000 <= 35000 < 50000
35000 <= 35000 < 60000
15900 <= 35000 < 55000

Budget End 40000 because
25000 < 40000 <= 40000
30000 < 40000 <= 50000
35000 < 40000 <= 60000
15900 < 40000 <= 55000

$start = Array(25000,30000,35000,15900);

$end = Array(40000,50000,60000,55000);

foreach($start as $val){
    $cnt = 0;
    for($i=0;$i<count($start); $i++){
        if($start[$i] <= $val && $val < $end[$i]){
            $cnt++;
        }
        if($cnt == count($start)){
            $start_budget = $val;
        }
    }
}

foreach($end as $val){
    $cnt = 0;
    for($i=0;$i<count($end); $i++){
        if($start[$i] < $val && $val <= $end[$i]){
            $cnt++;
        }
        if($cnt == count($end)){
            $end_budget = $val;
        }
    }
}

echo $start_budget;
echo "
";
echo $end_budget;
Posted in PHP.
function seo($input)
{
    //remove single quote and dash
    $input = str_replace(array("'", "-"), "", $input); 

    //convert to lowercase
    $input = mb_convert_case($input, MB_CASE_LOWER, "UTF-8"); 

    //replace everything non an with dashes
    $input = preg_replace("#[^a-zA-Z0-9]+#", "-", $input); 

    //replace multiple dashes with one
    $input = preg_replace("#(-){2,}#", "$1", $input);

    //trim dashes from beginning and end of string if any
    $input = trim($input, "-"); 
    
    //voila
    return $input; 
}

OP:
echo seo(“Tom’s Fish & Chips”); //toms-fish-chips
echo seo(“1-2-3 Pizza”); //123-pizza

	//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
	           }
	    }
	}
Posted in PHP.
 $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());
	 } 

Table Structure

 CREATE TABLE Areas(AreaName VARCHAR(255),
                    PinCode VARCHAR(255))
                    
INSERT INTO Areas(AreaName, PinCode)
          VALUES('Teynampet',   '6000018'), 
                ('Ramapuram',   '6000089'),
                ('TNagar',      '6000017'), 
                ('Mylapore',    '6000014'), 
                ('Gopalapuram', '6000087')

Procedure which returns multiple result sets

 DROP PROCEDURE IF EXISTS mp_test1;
 CREATE PROCEDURE mp_test1()
 BEGIN
   SELECT AreaName FROM Areas;
   SELECT PinCode FROM Areas; 
 END 

Procedure Call

 CALL mp_test1()

PHP Code To retrieve Records from Multiple Resultsets

   $mysqli	= new mysqli('localhost', 'root', '', 'test','3306');
	
   $query = "CALL mp_test1()";
	
   $i = 0;	
	
   if ($mysqli->multi_query($query)) 
   {
    do {		
	/* store first result set */
        if ($result = $mysqli->use_result()) 
	{
	  $j = 0;
	  
          while ($row = $result->fetch_row()) 
	  {
	     $arrResult[$i][$j] = $row[0];
	     $j++;
	  }
				
   	  $result->close();
         }
			
	if($mysqli->more_results()) 
	{
  	  $i = $i + 1;
	}			 
     } while ($mysqli->next_result());
   }
	
   print "
";
   print_r($arrResult);

How to Convert an Multidimensional Array to One Dimensional Array
//First Method with No Argument

$this->RestructArray($arrTempCounts)

//Second Method with  Column Name as Argument
$this->RestructArray($arrTemp, 'UserNums');

function RestructArray($parrInput, $pArg1 = 0)
{
	$arrTemp = $parrInput;
	
	for($i=0;$i<count($parrInput);$i++)
	{
		$arrNames[$i] = $parrInput[$i][$pArg1];
	}
	return $arrNames;
}

How to Convert an One Dimensional Array to Multidimensional Array

$k = 0;
for($j=0;$j<$lngCols;$j++)
{
	for($i=0;$i<$lngRows-1;$i++)
	{		
		$arrTemp[$j][$i] = $arrIndividualCounts[$k];
		$k = $k+1;
	}
}
Posted in PHP.