Posts

Showing posts from July, 2023

Update/Edit data in cakephp

 $this->Store->id = 28; $data = array(); $data['Store']['store_name'] = "Test Sarab Gen Store"; $this->Store->save($data);

PHP Curl Format

 try {             $url = "http://checkip.amazonaws.com";             $ch = curl_init();             $headers = array(                 'Accept: application/json',                 'Content-Type: application/json',             );             curl_setopt($ch, CURLOPT_URL, $url);             curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);             curl_setopt($ch, CURLOPT_HEADER, 0);             curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);             $result = curl_exec($ch);             $res = json_decode($result,true);                        $ip...

Find Laregest And 2nd Largest element in an array without function in Php

 <?php $testarray = array(4,3,8,5,2,9,7,6); $length =  count($testarray); for($i=0;$i<$length;$i++){ for($j=0;$j<$length-$i-1;$j++){ if ($testarray[$j]>$testarray[$j+1]) { $temp = $testarray[$j]; $testarray[$j] = $testarray[$j+1]; $testarray[$j+1] = $temp; } } } echo "Largest Element == ".$testarray[$length-1+1-1]; echo"<br>"; echo "2nd Largest Element == ".$testarray[$length-2+1-1]; ?> OutPut:- Largest Element == 9 2nd Largest Element == 8

Remove Duplicate elements from array in php

 <?php $duplicate = array(4,8,4,3,8,5,2,4,5,9,7,6,9); $length =  count($duplicate); $unique = array(); foreach($duplicate as $value){ if(!in_array($value,$unique)){ $unique[] = $value; } } echo"<pre>"; print_r($unique); ?> Output:- Array ( [0] => 4 [1] => 8 [2] => 3 [3] => 5 [4] => 2 [5] => 9 [6] => 7 [7] => 6 )

String reverse without function in php

 <?php $string = "i love india"; $rev =  ''; $length = strlen($string); for($i=$length-1;$i>=0;$i--){ $rev .=$string[$i]; } echo $rev; ?> Output:- aidni evol i

Merge Two array without function in php

<?php $array1 = array(1,2,3,4,5); $array2 = array(6,7,8,9,10); for($i=0;$i<count($array2);$i++){ $array1[] = $array2[$i]; } echo"<pre>"; print_r($array1); ?> Output:-   Array ( [0] => 1 [1] => 2 [2] => 3 [3] => 4 [4] => 5 [5] => 6 [6] => 7 [7] => 8 [8] => 9 [9] => 10 )

Reverse an array without function in php

<?php $array = array(9,8,7,6,5,4,3,2,1); $size = count ($array); $arrau_rev = array(); for($i = $size-1; $i>=0; $i--){ $arrau_rev[] = $array[$i]; } echo"<pre>"; print_r($arrau_rev); ?> Output:-   Array ( [0] => 1 [1] => 2 [2] => 3 [3] => 4 [4] => 5 [5] => 6 [6] => 7 [7] => 8 [8] => 9 )

Get All files of a folder in php or specific extension files

By PHP inbuild function glob() Return an array of filenames or directories that matches the specified pattern:  <?php print_r(glob("test/*.txt")); Output:- Array (   [0] => target.txt   [1] => source.txt   [2] => test.txt   [3] => test2.txt ) ?>

Sme meta base querys

 select * from SMEPROD.stores  where contact_number = '9966577499' order by id desc limit 20 select * from mfscore.tbl_send_sms order by insert_date desc limit 5 select * from SMEPROD.stores where api_key = '785ca71d2c85e3f3774baaf438c5c6eb' order by id desc limit 10 select * from SMEPROD.stores where contact_number = '9966577499' order by id desc limit 10 select * from SMEPROD.stores where contact_number = 8877112244 order by id desc limit 10 select * from mfscore.tbl_send_sms where msisdn = 8877112244 order by insert_date desc select * from mfscore.t_um_key_value where entity_id=21000000221; select * from mfscore.t_um_key_value where entity_id=21000000222; select * from mfscore.t_um_key_value limit 10; select * from mfscore.t_um_user_detail  where msisdn = 9966577499 select * from mfscore.t_um_user_identity  where msisdn = 9966577499 select * from mfscore.t_um_user_identity  where msisdn = 8067498242

Count Function Arguments and Receive all in a array

 By PHP inbuild function  func_get_args() && func_num_args() <?php    function test() {       $agsarr = func_get_args();        $num_arg = func_num_args();        echo "Number of arguments: " .$num_arg . "\n";       echo "<pre>";       print_r($agsarr);    }    test(1, 2, 3, 4, 5, 6, 7, 8); ?> Output:- Number of arguments: 8 Array (     [0] => 1     [1] => 2     [2] => 3     [3] => 4     [4] => 5     [5] => 6     [6] => 7     [7] => 8 )