bugfix> php > 投稿

この配列タイプのoutが必要でした。

Array
(
[2018-03-25] => Array
(
    [0] => Array
        (
            [loyalty_transcation_id] => 33
            [user_id] => 58
            [bill_copy_image_path] => 03252018_182712.jpg
            [create_date] => 2018-03-25 19:27:12
            [name] => bernd koch
        )
    [1] => Array
        (
            [loyalty_transcation_id] => 3
            [user_id] => 21
            [bill_copy_image_path] => 09132017_044456.jpg
            [create_date] => 2018-03-25 05:44:56
            [name] => Rahul Upadhyay
        )
)
[2017-09-27] => Array
(
    [0] => Array
        (
            [loyalty_transcation_id] => 10
            [user_id] => 24
            [bill_copy_image_path] => 09272017_115913.jpg
            [create_date] => 2017-09-27 12:59:13
            [name] => raj@ot.com
        )
    [1] => Array
        (
            [loyalty_transcation_id] => 3
            [user_id] => 21
            [bill_copy_image_path] => 09132017_044456.jpg
            [create_date] => 2017-09-27 05:44:56
            [name] => Rahul Upadhyay
        )
)
[2017-09-28] => Array
(
    [0] => Array
        (
            [loyalty_transcation_id] => 10
            [user_id] => 24
            [bill_copy_image_path] => 09272017_115913.jpg
            [create_date] => 2017-09-28 12:59:13
            [name] => raj@ot.com
        )
)

日付をキーとして使用してすべてのデータを保存し、1つの日付に複数の配列がある場合、データを同じキーにマージします。キーは異なるものであってはなりません。また、値が繰り返されない同じ日付を持つ他のすべての場合も、同じ手順で保存する必要があります。以下は私が書いたコードです。

$dups = $new_arr = array();
            foreach ($query->rows as $key => $val) {
                $new = date('Y-m-d', strtotime($val['create_date']));
                if (!isset($new_arr[$new])) {
                    $new_arr[$new] = $val;
                    //die;
                } else {
                    if (isset($dups[$new])) {
                       $dups[$new][] = $val;
                       //print_r($dups[$new]);
                      //echo "\n";
                    } else {
                       //$dups[$new] = array($val);
                       $dups[$new] = array($new_arr[$new], $value);
                    }
                }
            }
            //echo "<pre>";
            print_R($dups);
            die;

コードは、繰り返される値のデータのみを返し、繰り返されないデータを返しません。また、キーは正常に返されますが、値は別の日付からマージされます。どんな助けも感謝します。

ソートする入力配列:

Array
(
[0] => Array
    (
        [loyalty_transcation_id] => 36
        [user_id] => 23
        [bill_copy_image_path] => 05082018_144348.jpg
        [create_date] => 2018-05-08 15:43:48
        [name] => Admin
    )
[1] => Array
    (
        [loyalty_transcation_id] => 35
        [user_id] => 18
        [bill_copy_image_path] => 04052018_160009.jpg
        [create_date] => 2018-04-05 17:00:09
        [name] => gurpreet.singh@outlook.de
    )
[2] => Array
    (
        [loyalty_transcation_id] => 33
        [user_id] => 58
        [bill_copy_image_path] => 03252018_182712.jpg
        [create_date] => 2018-03-25 19:27:12
        [name] => bernd koch
    )
[3] => Array
    (
        [loyalty_transcation_id] => 32
        [user_id] => 57
        [bill_copy_image_path] => 03252018_160706.jpg
        [create_date] => 2018-03-25 17:07:06
        [name] => alex
    )
   )