Search
 
SCRIPT & CODE EXAMPLE
 

PHP

array flat php

$c = ["a" => ["x" => "X", "y" => "Y"], "b" => ["p" => "P", "q" => "Q"]];
print_r(array_merge(...array_values($c)));

Array
(
    [x] => X
    [y] => Y
    [p] => P
    [q] => Q
)
Comment

array_flatten php

/**
 * Function converts multidimentional array to a plain one
 *
 * @param $arr multidimensional array
 *
 * @return array
 */
function array_flatten($arr) {
    $return = [];
    foreach ($arr as $key => $value) {
        if (is_array($value)) {
            $return = array_merge($return, array_flatten($value));
        } else {
            $return[] = $value;
        }
    }
    return $return;
}
Comment

php flatten array

array_merge(...$a);
Comment

flatten in array php

array_merge(...$a);
Comment

flatten in array php

array_merge([], ...$a);
Comment

array flat php

$a = [[10, 20], [30, 40]];
$b = [["x" => "X", "y" => "Y"], ["p" => "P", "q" => "Q"]];

print_r(array_merge(...$a));
print_r(array_merge(...$b));

Array
(
    [0] => 10
    [1] => 20
    [2] => 30
    [3] => 40
)
Array
(
    [x] => X
    [y] => Y
    [p] => P
    [q] => Q
)
Comment

PREVIOUS NEXT
Code Example
Php :: php integer 
Php :: how to create foreign key in laravel 
Php :: object of class stdclass could not be converted to string php laravel 
Php :: php exit 
Php :: laravel import csv to database 
Php :: destruct php 
Php :: add phpmyadmin login linux 
Php :: laravel 9 excel 
Php :: spaceship operator php 
Php :: find substring php 
Php :: remove square brackets from string php 
Php :: php join 
Php :: asin() php 
Php :: remove last comma php 
Php :: global variable in laravel controller 
Php :: json get/post request in php 
Php :: how to know if file is empty in php 
Php :: where is in array laravel 
Php :: php split by 
Php :: laravel migration type to store html 
Php :: laravel collection methods 
Php :: laravel rate limit 
Php :: laravel run schedule only on production 
Php :: finding second highest number in array 
Php :: php input onchange 
Php :: laravel migration char length 
Php :: permutation and combination program in php 
Php :: guarded and fillable in laravel 
Php :: Remove the Breadcrumb on the Shop Page 
Php :: public variable in php 
ADD CONTENT
Topic
Content
Source link
Name
5+8 =