0
<?php 
$followed = Array(
    0=>array(
            'label' =>"label0",
            'id_poste'=>1,
            'id_part'=>11,
            'date'=>'9/12/21012'
    ),
    1=>array(
            'label' =>"label1",
            'id_poste'=>2,
            'id_part'=>12,
            'date'=>'10/13/21012'
            )
);

$unfollowed = Array(
    0=>array(
            'label' =>"New label",
            'id_poste'=>1,
            'id_part'=>11           
    )
);

これを実行して、2 つの配列をマージします。

$result = array_merge($followed, 
            array_udiff($unfollowed, $followed, 
                        function($a,$b){
                            return strcmp($a['label'],$b['label']);
                        }
           )
);

私は欲しいresult

    Array
(
    [0] => Array
        (
            [label] => label0
            [id_poste] => 1
            [id_part] => 11
            [date] => 9/12/21012
        )

    [1] => Array
        (
            [label] => label1
            [id_poste] => 2
            [id_part] => 12
            [date] => 10/13/21012
        )

    [2] => Array
        (
            [label] =>(A)New label /*concatenate with (A)*/
            [id_poste] => 1
            [id_part] => 11,
            [date]=>'--/--/----' /* Append new element with that format*/
        )

)

?>
4

1 に答える 1

1

次のコードを追加するだけです。

for($i=0;$i<count($unfollowed);$i++)
{
    $unfollowed[$i]['label'] ='(A)'.$unfollowed[$i]['label'];  
    $unfollowed[$i]['date'] ='--/--/----';
}
$result = array_merge($followed, $unfollowed);
于 2012-12-11T11:21:31.213 に答える