mardi 18 février 2020

How to sort associative array by specific order array keys in PHP/LARAVEL?

I'm initializing an array in my abstract class.

And I want to be sort this associative array in dynamically since the array index position has an effect when I export this as an excel sheet file.

public function setExportDetailsData() {
    $headers['barcode']            = Lang::get('core::label.barcode');
    $headers['stockNo']            = Lang::get('core::label.stock.no');
    $headers['productName']        = Lang::get('core::label.product.name');
    $headers['chineseName']        = Lang::get('core::label.chinese.name');
    $headers['category']           = Lang::get('core::label.category');
    $headers['discount2']          = Lang::get('core::label.discount.2');
    $headers['discount3']          = Lang::get('core::label.discount.3');
    $headers['discount4']          = Lang::get('core::label.discount.4');
    $headers['amount']             = Lang::get('core::label.amount');
    $headers['remarks']            = Lang::get('core::label.remarks');
}

I need to change the order it depending on the page/module sorting.

So, example, the order of sorting for page/module 1:

$sorting = [
    'stockNo',
    'barcode',
    'chineseName',
    'productName',
    'category',
    'discount2',
    'discount3',
    'discount4',
    'amount',
    'remarks'
];

And for other page/module has different page sorting.

I just want to sort this associative array dynamically depending on the page/module.



from Newest questions tagged laravel-5 - Stack Overflow https://ift.tt/38HB3kW
via IFTTT

1 commentaire:

  1. Do you understand there's a 12 word phrase you can say to your crush... that will induce deep feelings of love and instinctual attractiveness to you deep inside his heart?

    Because hidden in these 12 words is a "secret signal" that triggers a man's impulse to love, look after and look after you with all his heart...

    ===> 12 Words That Fuel A Man's Love Instinct

    This impulse is so hardwired into a man's brain that it will drive him to try harder than before to do his best at looking after your relationship.

    In fact, fueling this dominant impulse is absolutely important to achieving the best possible relationship with your man that once you send your man one of these "Secret Signals"...

    ...You'll immediately find him open his mind and soul to you in a way he haven't expressed before and he'll perceive you as the only woman in the world who has ever truly attracted him.

    RépondreSupprimer