PHP Array and Compressing Data

Following example shows that use of an array to sort records in ascending and descending order using PHP program.

<?php
$arr = array('Apple', 'Zensor', 'MITIndia');
echo "<br><b>Without sorted values are..</b><br>";

echo $arr[0], "<br>";
echo $arr[1], "<br>";
echo $arr[2], "<br>";

echo "<br><b>Sorted values are..</b><br>";
sort($arr);
$len=count($arr);
for($i=0; $i<$len; $i++)
{
echo $arr[$i], "<br>";
}

echo "<br><b>Reverse sorted values are..</b><br>";
rsort($arr);
$len=count($arr);
for($i=0; $i<$len; $i++)
{
echo $arr[$i], "<br>";
}
?>

Out put of the above program is… (function sort() to use display records in ascending and function rsort() to display in descending order.)

Array with sort

PHP Program to compress the data / text.

<?php
echo "<h1> Compress character with PHP </h1>";
echo "<hr>";
$str="Hello World Hello WorldHello WorldHello WorldHello 

WorldHello WorldHello WorldHello WorldHello WorldHello 

WorldHello WorldHello WorldHello WorldHello WorldHello 

WorldHello WorldHello WorldHello WorldHello WorldHello 

WorldHello WorldHello WorldHello World";
 
$compressed = gzcompress($str);
echo "Original file length: ". strlen($str)."\n";
echo "Compressed size: ". strlen($compressed)."\n";
?>

Output of the above program is…

Compress data using php function

PHP Program to display server date and time.

<?php
echo "Today date :", date("m/d/y");
echo "<br>The time is " . date("h:i:sA");
echo "<br>";
echo date('d-m-Y H:i');
echo "<br>";
?>

[m=month, d=day, y=year, h=hours, i=minutes, s=seconds  and A=ante meridiem]   Output of the above program is…

Time and date using php

Share

1 thought on “PHP Array and Compressing Data”

  1. game of thrones season 6 episode 10 online

    I loved as much as you’ll receive carried out right here.
    your authored subject matter stylish.

Comments are closed.

Share
Scroll to Top