Posts

Showing posts with the label php tricks

PHP.....Fundamental

 sorting as array of associative array.....using the value of perticular key: In ascending order: usort( $inventory , function ( $item1 , $item2 ) { return $item1 [ 'price' ] <=> $item2 [ 'price' ]; }); In descending order   usort( $inventory , function ( $item1 , $item2 ) { return $item2 [ 'price' ] <=> $item1 [ 'price' ]; });     Other solution : array_multisort(array_column( $inventory , 'price' ), SORT_DESC, $inventory ); If you want Case Insensitive Sort on strings, you can use SORT_NATURAL|SORT_FLAG_CASE array_multisort(array_column( $inventory , 'key_name' ), SORT_DESC, SORT_NATURAL|SORT_FLAG_CASE, $inventory );       count occurrences of values in an associative array in php $employees = array ( 1 => array ( 'name' => 'Jason Alipala' , 'employee_id' => 'G1001-05' , 'position' => 1 ), 2 => array ( ...

sitemap date format

  Date formating in sitemap.xml file for SEO:     The 'lastmod' element has to be of the format YYYY-MM-DD or YYYY-MM-DDThh:mmTZD so use: gmdate( 'Y-m-d' , strtotime($row[ 'modified' ][ 'value' ])) or gmdate( 'Y-m-d\TH:i:s+00:00' , strtotime($row[ 'modified' ][ 'value' ]))

Array & object sort

 <?php             $sel = mysqli_query($conn , "SELECT DISTINCT `lat_log` FROM `visitors`");             $num = mysqli_num_rows($sel);             $numArr = [];             if($num){                 while($r = mysqli_fetch_assoc($sel)){                     $city = $r['lat_log'];                     $selcount = mysqli_query($conn , "SELECT `id` FROM `visitors` WHERE `lat_log`='$city'");                     $ncount =...

csv file reader in php

<quote> <?php include 'connection.php'; $row = Array(); $headers = Array(); $tabColumn = Array(); $filename=''; $fileTemp=''; $tablename = ''; ?> <!DOCTYPE html> <html lang="en"> <head>     <meta charset="UTF-8">     <meta name="viewport" content="width=device-width, initial-scale=1.0">     <title>Campaign - info</title> <link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Roboto:300,400,500,700&display=swap"> <!-- Bootstrap core CSS --> <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css"> <link href="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/4.5.0/css/bootstrap.min.css" rel="stylesheet"> <!-- Material Design Bootstrap --> <link href="https://cdnjs.cloudflare.com/ajax/lib...