Tuesday, June 28, 2011

Postfix send my local emails as they are external emails !!!

If your machine address is host.domain.com your machine needs to know that this address is localhost.

/etc/hosts :
127.0.0.1 localhost   host.domain.com

Thursday, June 23, 2011

PHP - sort multidimentional array - order by column1, column2, ...

In sql we can do an order by occording to multiple columns

select sale_context, delivery_method, payment_method
FROM sales
order by 1, 2, 3

this query will output data ordered by sale_context then by delivery_method then by payment_method.

now I want to do the same thing with arrays in php,
I let my code explain how to do it


$data = array();
$data[] = array('sale_context' => 'internet',
'delivery_method'  => 'regular post',
'payment_method' => 'visa');

$data[] = array('sale_context' => 'phone',
'delivery_method'  => 'express post',
'payment_method' => 'mastercard');

$data[] = array('sale_context' => 'internet',
'delivery_method'  => 'regular post',
'payment_method' => 'cach');

$data[] = array('sale_context' => 'phone',
'delivery_method'  => 'express post',
'payment_method' => 'visa');
// order by sale_context, delivery_method, payment_method                                                                                                               
$sales_context_list = array();
$delivery_method_list = array();
$payment_method_list = array();

foreach($data AS $key => $row) {
$sales_context_list[] = $row['sale_context'];
$delivery_method_list[] = $row['delivery_method'];
$payment_method_list[] = $row['payment_method'];
}

echo "DATA BEFORE SORT";
print_r($data);

array_multisort($sales_context_list, SORT_ASC, $delivery_method_list, SORT_ASC, $payment_method_list, SORT_ASC, $data);
echo "DATA AFTER order by sale_context, delivery_method, payment_method ";
print_r($data);