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           
    )
);

这样做可以合并两个数组。

$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 回答