3

一个简单的事情,但我忘了如何转换

Array
(
    [0] => Array
        (
            [hashcode] => 952316176c1266c7ef1674e790375419
        )

    [1] => Array
        (
            [hashcode] => 5b821a14c98302ac40de3bdd77a37ceq
        )

)

进入这个:

Array (952316176c1266c7ef1674e790375419, 5b821a14c98302ac40de3bdd77a37ceq)
4

4 回答 4

5

我知道这还为时过早,但由于这即将到来,我想我把它扔在那里。从(尚未发布的)PHP 5.5 开始,您可以使用array_column()

 $hashcodes = array_column($array, 'hashcode');
于 2013-03-27T13:51:13.893 回答
4

尝试这个 :

$array  = array(array("test"=>"xcxccx"),array("test"=>"sdfsdfds"));

$result = call_user_func_array('array_merge', array_map("array_values",$array));

echo "<pre>";
print_r($result);

输出:

Array
(
    [0] => xcxccx
    [1] => sdfsdfds
)
于 2013-03-27T13:48:11.670 回答
2

一个好的ol'循环解决了:)

<?php

$array = array(
    array( 'hashcode' => 'hash' ),  
    array( 'hashcode' => 'hash2' ), 
);

$flat = array();

foreach ( $array as $arr ) {
    $flat[] = $arr['hashcode'];
}

echo "<pre>";

print_r( $flat );

?>
于 2013-03-27T13:52:28.097 回答
0
$source = array(
    array(
        'hashcode' => '952316176c1266c7ef1674e790375419'
    ),
    array(
        'hashcode' => '5b821a14c98302ac40de3bdd77a37ceq'
    )
);

$result = array();
array_walk($source, function($element) use(&$result){
    $result[] = $element['hashcode'];
});

echo '<pre>';
var_dump($result);
于 2013-03-27T13:54:42.383 回答