如何将数组get从result_array转换为普通数组

时间:2018-04-04 05:33:25

标签: php codeigniter

通过使用result_array我有这样的数组:

Array ( [0] => Array ( [toid] => 34 ) [1] => Array ( [toid] => 37 ) )    

但是,我想要正常的数组,因为我需要将其传递给查询。

2 个答案:

答案 0 :(得分:2)

您可以使用array_column

将多维数组转换为简单数组
$arr = .... //Your not so normal array here

$normalArr = array_column($arr, 'toid');

echo "<pre>";
print_r( $normalArr );
echo "</pre>";

这将导致:

Array
(
    [0] => 34
    [1] => 37
)

Doc:array_column

答案 1 :(得分:0)

//Old Array       
$Old_Array = array(
    array(
        "toid" => 34
    ),
    array(
        "toid" => 37
    )
);
//Output => Array ( [0] => Array ( [toid] => 34 ) [1] => Array ( [toid] => 37 ) ) 

//Converting to a normal New Array

$New_Array = array();
foreach ( $Old_Array as $Items ) 
    $New_Array[] = $Items["toid"];

//Output => Array ( [0] => 34 [1] => 37 )