0

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

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
    )
)
4

1 回答 1

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
}
于 2013-08-14T05:44:11.957 回答