Is there a function to make a copy of a PHP array to another?

前端 未结 19 2226
我寻月下人不归
我寻月下人不归 2020-12-07 06:44

Is there a function to make a copy of a PHP array to another?

I have been burned a few times trying to copy PHP arrays. I want to copy an array defined inside an obj

19条回答
  •  执念已碎
    2020-12-07 07:35

     $val ) {
                if( is_array( $val ) ) {
                    $result[$key] = arrayCopy( $val );
                } elseif ( is_object( $val ) ) {
                    $result[$key] = clone $val;
                } else {
                    $result[$key] = $val;
                }
            }
            return $result;
    }
    ?>
    

提交回复
热议问题