如何在codeigniter中将键转换为索引

时间:2013-08-14 05:33:15

标签: php arrays

我正在尝试做这样的事...... 我有一个像这样的数组结构

Array
(
    [0] => stdClass Object
        (
            [product_id1] => 15
            [product_id2] => 14
            [product_id3] => 0
            [product_id4] => 0
            [product_id5] => 0
        )

[1] => stdClass Object
    (
        [product_id1] => 15
        [product_id2] => 14
        [product_id3] => 0
        [product_id4] => 0
        [product_id5] => 0
    )

)

我希望将其转换为

Array
(
    [0] => stdClass Object
        (
            [0] => 15
            [1] => 14
            [2] => 0
            [3] => 0
            [4] => 0
        )
[1] => stdClass Object
    (
        [0] => 15
        [1] => 14
        [2] => 0
        [3] => 0
        [4] => 0
    )
)

1 个答案:

答案 0 :(得分:0)

你可以这样做:

$new = array_values( (array) $arr[0] );
print_r($new);

加入:

$final_arr = array();
foreach( $arr as $val ) {
    $tmpArr = array_values( (array)$val);
    $final_arr[] = (object) $tmpArr; //convert to object again
}