php

PHP Multidimentional Array sort

Posted on January 2, 2008. Filed under: php |

Ok friends , as promised i will be sharing my knowledge of php with you , in this series , here is my first script for you

This a very simple function on how to sort a multidimentional array in php

function sort_multi_array($mult_array , $field , $sort_type="ASC_NUM")
{

$code = '';
switch($sort_type) {

case ASC_NUM:
$code .= 'return strcmp($a["'.$field.'"], $b["'.$field.'"]);';
break;
case DESC_NUM:
$code .= 'return (-1*strcmp($a["'.$field.'"], $b["'.$field.'"]));';
break;
}

$compare = create_function('$a, $b', $code);
usort($mult_array, $compare);
return $mult_array;
}

//How to use :
$data[] = array('volume' => 67, 'date' => '2008-12-30 21:20:56', 'name' => "abc");
$data[] = array('volume' => 86, 'date' => '2007-12-25 21:20:56', 'name' =>'def' );
$data[] = array('volume' => 85, 'date' => '2007-12-27 21:20:56', 'name' => 'ghi');
$data[] = array('volume' => 05, 'date' => '2008-12-02 21:20:56', 'name' => 'jkl');
$data[] = array('volume' => 86, 'date' => '1975-12-05 21:20:56', 'name' => 'mno');
$data[] = array('volume' => 67, 'date' => '2007-12-30 20:20:56', 'name' => 'rto');

$data = sort_multi_array($data ,'date' , 'DESC_NUM');
var_dump($data);

/*

it will sort the array according to 'date'

array(6) {
[0]=>
array(3) {
["volume"]=>
int(67)
["date"]=>
string(19) "2008-12-30 21:20:56"
["name"]=>
string(3) "abc"
}
[1]=>
array(3) {
["volume"]=>
int(5)
["date"]=>
string(19) "2008-12-02 21:20:56"
["name"]=>
string(3) "jkl"
}
[2]=>
array(3) {
["volume"]=>
int(67)
["date"]=>
string(19) "2007-12-30 20:20:56"
["name"]=>
string(3) "rto"
}
[3]=>
array(3) {
["volume"]=>
int(85)
["date"]=>
string(19) "2007-12-27 21:20:56"
["name"]=>
string(3) "ghi"
}
[4]=>
array(3) {
["volume"]=>
int(86)
["date"]=>
string(19) "2007-12-25 21:20:56"
["name"]=>
string(3) "def"
}
[5]=>
array(3) {
["volume"]=>
int(86)
["date"]=>
string(19) "1975-12-05 21:20:56"
["name"]=>
string(3) "mno"
}
}

/*

Advertisements
Read Full Post | Make a Comment ( None so far )

PHP Vs ASP – a never ending saga —TFW#1

Posted on January 14, 2007. Filed under: asp, php, programming |

INTRODUCTION

PHP: PHP Hypertext Protocol:
PHP has become a somewhat mature dynamic server side programming language over the past few years. As of writing this article PHP 5.x is the current release and millions of web pages are using PHP (we are at Tizag). PHP is a free technology you can download for many different Operating Systems.

Compared to ASP, PHP is very easy to pick up and learn a little at a time. PHP is an ideal language for the weekend or hobbyist programmer. Seems like all green pastures in the land of PHP.

However, businesses do not readily embrace PHP for many reasons. A great deal of companies are running operating systems such as Windows Server 2003 or one of the Window NTs, which have been optimized to run Microsoft’s proprietary language ASP.

ASP: Active Service Pages
ASP is a technology that is included with Internet Information Services (IIS) which is included in Windows 2003, NTs and XP Professional. If you own XP Home Edition then you will need to pay a couple hundred dollars to upgrade to XP Professional before you can begin your ASP programming career.

As far as programming languages go, ASP is definitely not as straightforward as PHP. The language has a plethora of confusing programming patterns that will take a while to learn. Besides that difficulty, there is also much less free information on the internet, preventing you weekend programmers from getting a quality education for no money down.

On the other hand, ASP and ASP.NET are widely used in the business world. If you are looking to get a high paying job, ASP or ASP.NET would be a darn good start to improving your desirability to employers.

This isn’t to say that you couldn’t get a job with PHP, because you can, but rather you would just have an easier time if you took the ASP path. A search on Monster.com of ASP vs PHP near a major city resulted with 47 jobs for PHP and 321 jobs for ASP.

COMPARISON OF FEATURES

Cost
To run ASP programs one needs IIS installed on a Windows platform server, which is not free. PHP programs run on Linux, which is free. Even the connectivity of the database is expensive in the case of ASP as MS-SQL is a product of Microsoft that needs to be purchased. PHP generally uses MySQL, which is freely available

Speed
If we compare the speed of ASP and PHP then PHP has an upper hand. PHP code runs faster than ASP. ASP is built on COM based architecture, which is an overhead for the server whereas PHP code runs in its own memory space.

Platform Compatibility
PHP programs can run on various platforms like Linux, Unix, Windows and Solaris whereas ASP is mainly associated with Windows platforms. However, ASP can run on a Linux platform with ASP-Apache installed on the server.

Additional Costs
Many of the tools used in PHP are free of cost and since PHP is open source a lot of code can be found in open source forums. PHP has inbuilt features like ftp, email from a web page or even encryption mechanisms but in ASP such features are not built in and some additional components are required. Therefore an additional cost is incurred for such components

Base Language
PHP is based on C++ language and the syntax used in PHP is quite similar to C/C++. C/C++ is still considered the best programming language by many programmers and people who love this language would surely feel more comfortable with the syntax of PHP. ASP on the other hand has a more Visual Basic kind of syntax that again is closely related to only Microsoft products. So, it depends on a person-to-person which language he or she is comfortable

CONCLUSION

So , it depends on the person , which language is to follow. If we see the easiness , php is much better to follow . Cost , speed , online support and many other things supports php . There are very few things which php can do but asp cant. But still asp gets upper hand when it comes to making a portal site website. For young programmers , it is advisable to choose asp as it will benefit them career wise.

Copyright Notice : The data for above article was taken from various websites and forum posts .
http://www.pointafter.com/Archives/nl0203.htm
http://www.webpronews.com/expertarticles/expertarticles/wpn-62-20051222ASPvsPHP.html

Also See
http://www.sitepoint.com/article/v-php-top-6-reasons-use-net

Read Full Post | Make a Comment ( 4 so far )

Liked it here?
Why not try sites on the blogroll...