Posts

Design Patterns

Image
  Design patterns  are typical solutions to commonly occurring problems in software design. They are like pre-made blueprints that you can customize to solve a recurring design problem in your code The Catalog of Design Patterns Creational Design Patterns These patterns provide various object creation mechanisms, which increase flexibility and reuse of existing code. Structural patterns These patterns explain how to assemble objects and classes into larger structures while keeping these structures flexible and efficient. Behavioral patterns These patterns are concerned with algorithms and the assignment of responsibilities between objects. https://refactoring.guru/design-patterns

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 )