1

我有一个数组,想删除它的键值..它们是 0 ,1 等等..数组有动态值。关键指标可以动态增加或减少。

$url = Array 
        (
            0 => Array
            (
                'youtube ' => Array
                (
                    'youtube.com' => "https://www.youtube.com/dfssfskj8i"
                ),
            ),

            1 => Array
            (
                'youtube' => Array
                (
                    'youtube.com' => 'https://www.youtube.com/sfsfsd'
                ),
            )
        );



$temp = array();
foreach($url as $key => $val){
    foreach($val as $key1 => $val1){
        $temp[$key1][$val1] = $key1; 
    }
}                

我需要输出

Array 
    (

        'youtube ' => Array
        (
            'youtube.com' => "https://www.youtube.com/dfssfskj8i"

        ),

        'youtube' => Array
        (
            'youtube.com' => 'https://www.youtube.com/sfsfsd'
        ),
    );
4

2 回答 2

3

也许你正在尝试做这样的事情:

$out = array();
foreach ($url as $key => $value){
    $dex = key($value);
    $out[$dex][] = reset($value[$dex]);
}
print_r($out);

如果您在键入“youtube”后摆脱了多余的空间,您将获得以下输出:

Array
(
    [youtube] => Array
        (
            [0] => https://www.youtube.com/dfssfskj8i
            [1] => https://www.youtube.com/sfsfsd
        )

)
于 2013-08-08T11:22:37.157 回答
0

尝试这个,

$url = Array 
    (
        0 => Array
        (
            'youtube ' => Array
            (
                'youtube.com' => "https://www.youtube.com/dfssfskj8i"
            ),
        ),

        1 => Array
        (
            'youtube' => Array
            (
                'youtube.com' => 'https://www.youtube.com/sfsfsd'
            ),
        )
    );

$temp = array();
foreach($url as $key => $val){
  foreach($val as $key1 => $val1){
     $temp[$key1] = $val1; 
  }
}  
于 2013-08-08T12:08:42.063 回答