Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- // bench
- //$t = microtime(true);
- //$array = array();
- //for($i = 0; $i < 1000000; $i++) {
- // $array[] = $i;
- //}
- //print microtime(true) - $t;
- //print "\n";
- //$t = microtime(true);
- //$array = array();
- //for($i = 0; $i < 1000000; $i++) {
- // array_push($array, $i);
- //}
- //print microtime(true) - $t;
- $a = [
- 'tt',
- 'tttt',
- [
- 'asd',
- 'dsa',
- ],
- 'ddd',
- 'bbb'
- ];
- print_r($a);
- $new = [];
- foreach($a as $val) {
- if ( ! is_array( $val ) ) {
- $new[] = $val;
- continue;
- }
- // можно и так, но это медленнее
- // array_push( $new, ...$val );
- // Такой вариант быстрее в среднем на 50-70%
- foreach($val as $v) {
- $new[] = $v;
- }
- }
- print_r($new);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement