通过检查整个数组来分离数组

时间:2014-12-09 08:11:55

标签: php codeigniter

  • 下面是样本数组,其中整个数组中的[a]和[b]键的值为'aa',[a]和[b]键的值为'bb'。

  • 如果这些是匹配的,则应将其分开,如下所示。这应该是动态发生的。


Array
(
    [0] => Array
        (
            [a] => aa  //this is matching with 3rd array with b key
            [b] => bb

        )

    [1] => Array
        (
            [a] => bb
            [b] => cc
        )

    [2] => Array
        (
            [a] => cc
            [b] => bb
        )

    [3] => Array
        (
            [a] => bb
            [b] => aa  //this is matching with 0th array with a key
        )

)

以下是我想要的输出

Array
(
    [0] => Array
        (
            [a] => aa  
            [b] => bb

        )

    [1] => Array
        (
            [a] => bb
            [b] => cc
        )
)

Array
(

    [2] => Array
        (
            [a] => cc
            [b] => bb
        )

    [3] => Array
        (
            [a] => bb
            [b] => aa
        )

)

这就是我试过的方法,即使我粘贴代码,下面的方法也不正确。

$array_count = count($onw_return); // $onw_return is the complete array
$jk = count($onw_return)-1; 
for($jj=0;$jj<$array_count;$jj++)
{
if( in_array($onw_return[$jj]['sour'],$onw_return)){
echo "aa"; //this should come 2 times
}else{
echo  "bb";//this should come 2 times
}
$jk--;
}

0 个答案:

没有答案