PHP code example of didacelgueta / flatten-multidimensional-array
1. Go to this page and download the library: Download didacelgueta/flatten-multidimensional-array library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
didacelgueta / flatten-multidimensional-array example snippets
use Didacelgueta\FlattenMultidimensionalArray;
$two_dimansional_array = array(
'a' => 1,
'b' => array('c' => 2, 'd' => 3)
);
// Reduce the dimensionality by calling 'array_flatten' class method
$result = FlattenMultidimensionalArray::array_flatten($two_dimansional_array)
var_dump($result);
[
'a' => 1,
'b.c' => 2,
'b.d' => 3
]
$arg = array(
'a' => 1,
'b' => [
'c' => 2,
'd' => 3
]
);
$result = FlattenMultidimensionalArray::array_flatten($arg, '_');
var_dump($result);
[
'a' => 1,
'b_c' => 2,
'b_d' => 3
]