This is the result of array after i build it using array_push function from mssql result.
Array
(
[0] => Array
(
[STICKER] => FALCON
[MONTH] => 1
[JUM] => 65826210.00
)
[1] => Array
(
[STICKER] => FALCON
[MONTH] => 2
[JUM] => 68070573.00
)
[2] => Array
(
[STICKER] => FALCON
[MONTH] => 3
[JUM] => 99053067.60
)
[3] =>
[4] => Array
(
[STICKER] => HRD
[MONTH] => 2
[JUM] => 1521400.00
)
[5] => Array
(
[STICKER] => HRD
[MONTH] => 3
[JUM] => 2093200.00
)
)
I need to convert array above into this structure:
Array
(
[0] => Array
(
[0] =>
[1] => 1
[2] => 2
[3] => 3
)
[1] => Array
(
[0] => FALCON
[1] => 65826210.00
[2] => 68070573.00
[3] => 99053067.60
)
[2] => Array
(
[0] => HRD
[1] => 0
[2] => 1521400.00
[3] => 2093200.00
)
)
Note:
Array[0] values would be 1,2,3 (this is actualy month, i just input up to 3 in order to get the code not too long. but it will be up to 12 (Jan - Dec)).
If from original array, there is none value (example from array[3]), then it will be convert to new array[2]->[1] with value 0.
Any help would be very appreciated.
Thanks all!.
Try this,
If any month is not mentioned from stickers the jum considered as 0,
$array = array(
array('STICKER' => 'FALCON', 'MONTH' => 1, 'JUM' => 65826210.00),
array('STICKER' => 'FALCON', 'MONTH' => 2, 'JUM' => 68070573.00),
array('STICKER' => 'FALCON', 'MONTH' => 3, 'JUM' => 99053067.60),
array(),
array('STICKER' => 'HRD', 'MONTH' => 2, 'JUM' => 1521400.00),
array('STICKER' => 'HRD', 'MONTH' => 3, 'JUM' => 2093200.00),
);
$result[0][] = '';
foreach ($array as $key => $res) {
if (!empty($res)) {
$result[0][$res['MONTH']] = $res['MONTH'];
$result1[$res['STICKER']][$res['MONTH']] = $res['JUM'];
}
}
foreach ($result1 as $key => $res) {
$fin = array();
foreach ($res as $key1 => $re) {
foreach ($result[0] as $key2 => $month) {
if ($month != '') {
if (array_key_exists($month, $res)) {
if (!array_key_exists($month, $fin) && $month == $key1) {
$fin[$month] = $re;
}
} else {
$fin[$month] = 0;
}
}
}
}
$result[] = array_merge(array($key), $fin);
}
echo'<pre>';
print_r($result);
echo'<pre>';
Result:
Array
(
[0] => Array
(
[0] =>
[1] => 1
[2] => 2
[3] => 3
)
[1] => Array
(
[0] => FALCON
[1] => 65826210
[2] => 68070573
[3] => 99053067.6
)
[2] => Array
(
[0] => HRD
[1] => 0
[2] => 1521400
[3] => 2093200
)
)
I hope this is used to achieve your output(you mentioned in above question)!!
try something like this
not the issue with the empty array i could not understand how the program would know that it is STICKER HRD so it will be filled with zero.But you could later check if every month "isset" and if it is not act as it is zero
$arr1=array(
array('STICKER'=>'FALCON','MONTH'=>1,'JUM'=>65826210.00),
array('STICKER'=>'FALCON','MONTH'=>2,'JUM'=>68070573.00),
array('STICKER'=>'FALCON','MONTH'=>3,'JUM'=>99053067.60),
array(),
array('STICKER'=>'HRD','MONTH'=>2,'JUM'=>1521400.00),
array('STICKER'=>'HRD','MONTH'=>3,'JUM'=>2093200.00),
);
$arr2=array();
$arr3=array();
$arr2[0][0]="";
foreach($arr1 as $key => $val){
if(!empty($val)){
$arr2[0][$val['MONTH']]=$val['MONTH'];
//group each STICKER
$arr3[$val['STICKER']][]=$val['JUM'];
}
}
//transfer the grouped data to arr2
foreach($arr3 as $key => $val){
$tmp_arr=array($key);
$arr2[]=array_merge($tmp_arr,$val);
}
print_r($arr2);
Related
I have 2 Array:
$arr1 = Array (
[2] => Array ( [0] => 41000 [1] => 31079 )
[3] => Array ( [0] => 42963 [1] => 41189 )
)
$arr2 = Array (
[2] => Array ( [0] => 40213 [1] => 42054 )
[3] => Array ( [0] => 42998 [1] => 34567 )
)
I want to combine these two arrays to this array with same key:
$arr3 = Array (
[2] => Array ( [0] => 40213 [1] => 42054 [2] => 41000 [3] => 31079 )
[3] => Array ( [0] => 42998 [1] => 34567 [2] => 42963 [3] => 41189 )
)
I tried almost anything (merge, combine, join) but I can't figure it out. Any suggestions?
This is a nice and easy thing to do.
$arr1 = [2 => [0 => 41000, 1 => 31079], 3 => [0 => 42963, 1 => 41189]];
$arr2 = [2 => [0 => 40213, 1 => 42054], 3 => [0 => 42998, 1 => 34567]];
function addArray(&$bucket, $water)
{
foreach ($water as $key => $drop) {
$bucket[$key] = array_merge($bucket[$key] ?? [], $drop);
}
}
$combined = [];
addArray($combined, $arr1);
addArray($combined, $arr2);
var_export($combined);
See a PHP fiddle here.
The output is:
array (
2 =>
array (
0 => 41000,
1 => 31079,
2 => 40213,
3 => 42054,
),
3 =>
array (
0 => 42963,
1 => 41189,
2 => 42998,
3 => 34567,
),
)
How does it work? I wrote a little function that would add the input arrays to an array that combines all arrays.
$arr1 = array(
2 => array(41000, 31079),
3 => array(42963, 41189)
);
$arr2 = array(
2 => array(40213, 42054),
3 => array(42998, 34567)
);
$arr3 = array();
foreach($arr1 as $key => $values){
if(!isset($arr3[$key])){
$arr3[$key] = array();
}
$arr3[$key] = array_merge($arr3[$key], $values);
}
foreach($arr2 as $key => $values){
if(!isset($arr3[$key])){
$arr3[$key] = array();
}
$arr3[$key] = array_merge($arr3[$key], $values);
}
echo '<pre>';
print_r($arr3);
Prints:
Array
(
[2] => Array
(
[0] => 41000
[1] => 31079
[2] => 40213
[3] => 42054
)
[3] => Array
(
[0] => 42963
[1] => 41189
[2] => 42998
[3] => 34567
)
)
Actual Array
Array
(
[0] => Array
(
[sub_id] => 3
[sub_name] => tttt
[master_id] => 3
)
[1] => Array
(
[sub_id] => 4
[sub_name] => yyyy
[master_id] => 3
)
[2] => Array
(
[sub_id] => 5
[sub_name] => kkkk
[master_id] => 4
)
)
Expected Result
Array
(
[3] => Array(
[0] => Array
(
[sub_id] => 3
[sub_name] => tttt
[master_id] => 3
)
[1] => Array
(
[sub_id] => 4
[sub_name] => yyyy
[master_id] => 3
)
)
[4] => Array(
[0] => Array
(
[sub_id] => 5
[sub_name] => kkkk
[master_id] => 4
)
)
)
You can create a new array and set value of master id as the index and put the value in it.
$data = array();
foreach($array as $key=>$value){
$data[$value['master_id']][] = $value;
}
$actualArray = array(array('sub_id' => 3, 'sub_name' => 'tttt', 'master_id' => 3),array('sub_id' => 4, 'sub_name' => 'yyyy', 'master_id' => 3),array('sub_id' => 5, 'sub_name' => 'kkkk', 'master_id' => 4));
$tempArray = array_unique(array_column($actualArray, 'master_id'));
$uniqueArray = array_intersect_key($actualArray, $tempArray);
foreach ($uniqueArray as $key => $masters) {
$count = 0;
foreach ($actualArray as $key1 => $actuals) {
if($masters['master_id'] == $actuals['master_id']){
$expectedArray[$key][$count] = $actuals;
$count++;
}
}
}
Array
(
[681074CRPAK4] => Array
(
[0] => 681074
[1] => 681074CRPAK4
[2] => 5602385431605
)
[681520XXXP6L] => Array
(
[0] => 681520
[1] => 681520XXXP6L
[2] => 5602385667394
)
[681530XXXP6V] => Array
(
[0] => 681530
[1] => 681530XXXP6V
[2] => 5602385667417
)
[681530XXXP6W] => Array
(
[0] => 681530
[1] => 681530XXXP6W
[2] => 5602385667424
)
[681530XXXP6X] => Array
(
[0] => 681530
[1] => 681530XXXP6X
[2] => 5602385667400
)
)
I want to compare the value of key[0] of each array.
If they are the same then I would like to add a new key[3] to each array with an id.
This is an array of variable products if the product has the same key[0] then its the same product with different variations.
If the key[0] is different from the previous then add id+1, in this example, I would like to end up with:
Array
(
[681074CRPAK4] => Array
(
[0] => 681074
[1] => 681074CRPAK4
[2] => 5602385431605
[3] => 1
)
[681520XXXP6L] => Array
(
[0] => 681520
[1] => 681520XXXP6L
[2] => 5602385667394
[3] => 2
)
[681530XXXP6V] => Array
(
[0] => 681530
[1] => 681530XXXP6V
[2] => 5602385667417
[3] => 3
)
[681530XXXP6W] => Array
(
[0] => 681530
[1] => 681530XXXP6W
[2] => 5602385667424
[3] => 3
)
[681530XXXP6X] => Array
(
[0] => 681530
[1] => 681530XXXP6X
[2] => 5602385667400
[3] => 3
)
)
can you guys help me with this?
I tried this:
but does not work
foreach ($new as $current_key => $current_array) {
foreach ($new as $search_key => $search_array) {
$ref1 = $current_array[0];
$ref2 = $search_array[0];
if (($search_key != $current_key) and ($ref1 == $ref2)) {
$current_array[3] = $p_id_product;
}
else{
$current_array[3] = $p_id_product++;
}
}
}
Assuming you have already sorted the array by the initial index, so at least they are grouped:
<?php
$data =
[
[
'foo',
'spam',
'bar',
],
[
'foo',
'eggs',
],
[
'bar',
'ham'
],
];
$output = [];
$counter = 0;
$last = null;
foreach($data as $k => $v) {
if($last !== $v[0])
$counter++;
$v[3] = $counter;
$output[$k] = $v;
$last = $v[0];
}
var_export($output);
Output:
array (
0 =>
array (
0 => 'foo',
1 => 'spam',
2 => 'bar',
3 => 1,
),
1 =>
array (
0 => 'foo',
1 => 'eggs',
3 => 1,
),
2 =>
array (
0 => 'bar',
1 => 'ham',
3 => 2,
),
)
I have an array which holds some articles of a website. The problem is: when the same article is in 2 different categories it only shows 1. In this example the categories are 'Service' and 'Sales'.
If the article is duplicate and the category is 'Sales' I want 1 of them to change to 'Service' and vice versa.
The array I got now(3 & 4 as duplicates and 7 & 8):
Array
(
[0] => Array
(
[0] => Sales
[1] => assistentiesystemen
[2] => www.youtube.com/video/38BbjLmVJXk
[3] => Park assist
)
[1] => Array
(
[0] => Sales
[1] => assistentiesystemen
[2] => www.youtube.com/video/3lGfTZdVK1s
[3] => Multi Collision braking system
)
[2] => Array
(
[0] => Sales
[1] => assistentiesystemen
[2] => www.youtube.com/video/6mgDraWpGvE
[3] => Area view
)
[3] => Array
(
[0] => Sales
[1] => assistentiesystemen
[2] => www.youtube.com/video/II68oVm4zro
[3] => Lane Assist
)
[4] => Array
(
[0] => Sales
[1] => assistentiesystemen
[2] => www.youtube.com/video/II68oVm4zro
[3] => Lane Assist
)
[5] => Array
(
[0] => Sales
[1] => assistentiesystemen
[2] => www.youtube.com/video/N0fa4dUBkvE
[3] => Trailer assist
)
[6] => Array
(
[0] => Service
[1] => veilig-op-de-weg
[2] => www.youtube.com/video/NCNDyW6Yr1g
[3] => Ruitenwissers
)
[7] => Array
(
[0] => Service
[1] => veilig-op-de-weg
[2] => www.youtube.com/video/PJEC-yqUwzE
[3] => Bandenafdichtset
)
[8] => Array
(
[0] => Service
[1] => veilig-op-de-weg
[2] => www.youtube.com/video/PJEC-yqUwzE
[3] => Bandenafdichtset
)
)
The array I want to accomplish (No duplicates anymore and the values changed):
Array
(
[0] => Array
(
[0] => Sales
[1] => assistentiesystemen
[2] => www.youtube.com/video/38BbjLmVJXk
[3] => Park assist
)
[1] => Array
(
[0] => Sales
[1] => assistentiesystemen
[2] => www.youtube.com/video/3lGfTZdVK1s
[3] => Multi Collision braking system
)
[2] => Array
(
[0] => Sales
[1] => assistentiesystemen
[2] => www.youtube.com/video/6mgDraWpGvE
[3] => Area view
)
[3] => Array
(
[0] => Service
[1] => assistentiesystemen
[2] => www.youtube.com/video/II68oVm4zro
[3] => Lane Assist
)
[4] => Array
(
[0] => Sales
[1] => assistentiesystemen
[2] => www.youtube.com/video/II68oVm4zro
[3] => Lane Assist
)
[5] => Array
(
[0] => Sales
[1] => assistentiesystemen
[2] => www.youtube.com/video/N0fa4dUBkvE
[3] => Trailer assist
)
[6] => Array
(
[0] => Service
[1] => veilig-op-de-weg
[2] => www.youtube.com/video/NCNDyW6Yr1g
[3] => Ruitenwissers
)
[7] => Array
(
[0] => Sales
[1] => veilig-op-de-weg
[2] => www.youtube.com/video/PJEC-yqUwzE
[3] => Bandenafdichtset
)
[8] => Array
(
[0] => Service
[1] => veilig-op-de-weg
[2] => www.youtube.com/video/PJEC-yqUwzE
[3] => Bandenafdichtset
)
)
What I tried:
$length = count ($sorted);
for ($c = 0; $c < $length; $c++) {
$check_array = $sorted[$c];
for ($x = 0; $x < $length; $x++) {
$compare_array = $sorted[$x];
if ($x != $i){
if($check_array[2] == $compare_array[2] && $check_array[0] == $compare_array[0]){
//print_r ($check_array);
//print_r ($compare_array);
if($check_array[0] == 'Sales'){
$compare_array[0] = 'Service';
}
if($check_array[0] == 'Service'){
$compare_array[0] = 'Sales';
}
}
}
}
}
Any help will be much appreciated.
Put your data in $array variable and try it:
$hash = array_map( function ( $value ) { return md5( implode( $value ) ); } , $array);
$keys = array_keys( array_diff_assoc( $hash, array_unique( $hash ) ) );
foreach( $keys as $key )
$array[ $key ][0] = $array[ $key ][0] == 'Service' ? 'Sales' : 'Service';
If the order is not important for you, you can use array_multisort, array_column and array_walk:
$replacements = [
'Sales' => 'Service',
'Service' => 'Sales'
];
// Sort array by youtube url.
array_multisort($array, array_column($array, 2));
array_walk($array, function (&$curr, $_, &$prev) use ($replacements) {
if (
$prev !== null
&& $prev[2] === $curr[2]
) {
$curr[0] = $replacements[$curr[0]];
}
$prev = $curr;
}, null);
Here is working demo.
Here I have a written some code, you can try it.
<?php
$array = [
[
0 => 'Sales',
1 => 'assistentiesystemen',
2 => 'www.youtube.com/video/38BbjLmVJXk',
3 => 'Park assist',
],
[
0 => 'Sales',
1 => 'assistentiesystemen',
2 => 'www.youtube.com/video/3lGfTZdVK1s',
3 => 'Multi Collision braking system'
],
[
0 => 'Sales',
1 => 'assistentiesystemen',
2 => 'www.youtube.com/video/6mgDraWpGvE',
3 => 'Area view'
],
[
0 => 'Sales',
1 => 'assistentiesystemen',
2 => 'www.youtube.com/video/II68oVm4zro',
3 => 'Lane Assist'
],
[
0 => 'Sales',
1 => 'assistentiesystemen',
2 => 'www.youtube.com/video/II68oVm4zro',
3 => 'Lane Assist'
],
[
0 => 'Sales',
1 => 'assistentiesystemen',
2 => 'www.youtube.com/video/N0fa4dUBkvE',
3 => 'Trailer assist'
],
[
0 => 'Service',
1 => 'veilig-op-de-weg',
2 => 'www.youtube.com/video/NCNDyW6Yr1g',
3 => 'Ruitenwissers'
],
[
0 => 'Service',
1 => 'veilig-op-de-weg',
2 => 'www.youtube.com/video/PJEC-yqUwzE',
3 => 'Bandenafdichtset'
],
[
0 => 'Service',
1 => 'veilig-op-de-weg',
2 => 'www.youtube.com/video/PJEC-yqUwzE',
3 => 'Bandenafdichtset'
]
];
/**
* #param $firstIndexValue
* #param $thirdIndexValue
* #param $searchArray
* #return bool
*/
function isExistValue($firstIndexValue, $thirdIndexValue, $searchArray)
{
foreach ($searchArray as $element) {
if ($firstIndexValue == $element[0] && $thirdIndexValue == $element[3]) {
return true;
}
}
return false;
}
$newArray = [];
foreach ($array as $arr) {
$isExist = isExistValue($arr[0], $arr[3], $newArray);
if ($isExist) {
if ($arr[0] == 'Sales') {
$arr[0] = 'Service';
} elseif ($arr[0] == 'Service') {
$arr[0] = 'Sales';
}
}
$newArray[] = $arr;
}
var_dump($newArray);
I have following array with php code
I could not find where I am mistaken
I'm trying to filter some of these array results and delete them. When I try to list them I could not succeded
array (
0 => 'do-update.php',
1 => 'sitemap.xml',
2 => 'sitemap.xml.gz',
3 => 'wp-config.php',
'wp-content' =>
array (
'uploads' =>
array (
2013 =>
array (
'05' =>
array (
0 => 'kabeduvarkad-1024x768.jpg',
1 => 'kabeduvarkad-150x150.jpg',
2 => 'kabeduvarkad-300x225.jpg',
3 => 'kabeduvarkad-940x198.jpg',
4 => 'kabeduvarkad.jpg',
5 => 'kabeduvarkad1-1000x288.jpg',
6 => 'kabeduvarkad1-1024x768.jpg',
7 => 'kabeduvarkad1-150x150.jpg',
8 => 'kabeduvarkad1-300x225.jpg',
9 => 'kabeduvarkad1-400x300.jpg',
10 => 'kabeduvarkad1.jpg',
11 => 'kabeduvarkad2-1000x288.jpg',
12 => 'kabeduvarkad2-1024x768.jpg',
13 => 'kabeduvarkad2-150x150.jpg',
14 => 'kabeduvarkad2-300x225.jpg',
15 => 'kabeduvarkad2-400x300.jpg',
16 => 'kabeduvarkad2.jpg',
),
10 =>
array (
),
),
2014 =>
array (
'02' =>
array (
),
),
),
),
'wp-update' =>
array (
0 => 'wp-update.tar',
1 => 'wp-update.tar.gz',
2 => 'wp-update1.tar',
3 => 'wp-update1.tar.gz',
),
4 => 'wp-update.tar.gz',
)
This is my function
function listArrayRecursive($array_name, $ident = ''){
$result = array();
foreach ($array_name as $k => $v){
if (is_array($v)){
$result[] = listArrayRecursive($v, $ident.'/'.$k);
}else{
$result[] = $ident. '/' . $v . '<br>';
}
}
return $result;
}
I have following result
Array
(
[0] => /do-update.php<br>
[1] => /sitemap.xml<br>
[2] => /sitemap.xml.gz<br>
[3] => /wp-config.php<br>
[4] => Array
(
[0] => Array
(
[0] => Array
(
[0] => Array
(
[0] => /wp-content/uploads/2013/05/kabeduvarkad-1024x768.jpg<br>
[1] => /wp-content/uploads/2013/05/kabeduvarkad-150x150.jpg<br>
[2] => /wp-content/uploads/2013/05/kabeduvarkad-300x225.jpg<br>
[3] => /wp-content/uploads/2013/05/kabeduvarkad-940x198.jpg<br>
[4] => /wp-content/uploads/2013/05/kabeduvarkad.jpg<br>
[5] => /wp-content/uploads/2013/05/kabeduvarkad1-1000x288.jpg<br>
[6] => /wp-content/uploads/2013/05/kabeduvarkad1-1024x768.jpg<br>
[7] => /wp-content/uploads/2013/05/kabeduvarkad1-150x150.jpg<br>
[8] => /wp-content/uploads/2013/05/kabeduvarkad1-300x225.jpg<br>
[9] => /wp-content/uploads/2013/05/kabeduvarkad1-400x300.jpg<br>
[10] => /wp-content/uploads/2013/05/kabeduvarkad1.jpg<br>
[11] => /wp-content/uploads/2013/05/kabeduvarkad2-1000x288.jpg<br>
[12] => /wp-content/uploads/2013/05/kabeduvarkad2-1024x768.jpg<br>
[13] => /wp-content/uploads/2013/05/kabeduvarkad2-150x150.jpg<br>
[14] => /wp-content/uploads/2013/05/kabeduvarkad2-300x225.jpg<br>
[15] => /wp-content/uploads/2013/05/kabeduvarkad2-400x300.jpg<br>
[16] => /wp-content/uploads/2013/05/kabeduvarkad2.jpg<br>
)
[1] => Array
(
)
)
[1] => Array
(
[0] => Array
(
)
)
)
)
[5] => Array
(
[0] => /wp-update/wp-update.tar<br>
[1] => /wp-update/wp-update.tar.gz<br>
[2] => /wp-update/wp-update1.tar<br>
[3] => /wp-update/wp-update1.tar.gz<br>
)
[6] => /wp-update.tar.gz<br>
)
Expected Result is
Array
(
[0] => /do-update.php<br>
[1] => /sitemap.xml<br>
[2] => /sitemap.xml.gz<br>
[3] => /wp-config.php<br>
[4] => /wp-content/uploads/2013/05/kabeduvarkad-1024x768.jpg<br>
[5] => /wp-content/uploads/2013/05/kabeduvarkad-150x150.jpg<br>
[6] => /wp-content/uploads/2013/05/kabeduvarkad-300x225.jpg<br>
[7] => /wp-content/uploads/2013/05/kabeduvarkad-940x198.jpg<br>
[8] => /wp-content/uploads/2013/05/kabeduvarkad.jpg<br>
[9] => /wp-content/uploads/2013/05/kabeduvarkad1-1000x288.jpg<br>
[10] => /wp-content/uploads/2013/05/kabeduvarkad1-1024x768.jpg<br>
[11] => /wp-content/uploads/2013/05/kabeduvarkad1-150x150.jpg<br>
[12] => /wp-content/uploads/2013/05/kabeduvarkad1-300x225.jpg<br>
[13] => /wp-content/uploads/2013/05/kabeduvarkad1-400x300.jpg<br>
[14] => /wp-content/uploads/2013/05/kabeduvarkad1.jpg<br>
...
[110] => /wp-update/wp-update.tar<br>
[111] => /wp-update/wp-update.tar.gz<br>
[112] => /wp-update/wp-update1.tar<br>
[113] => /wp-update/wp-update1.tar.gz<br>
[114] => /wp-update.tar.gz<br>
)
You can do it like this:
<?php
// Dummy data source
$data = array(
'/do-update.php',
'/sitemap.xml',
'/sitemap.xml.gz',
'/wp-config.php',
array(
array(
array(
'/wp-content/uploads/2013/05/kabeduvarkad-1024x768.jpg',
'/wp-content/uploads/2013/05/kabeduvarkad-150x150.jpg',
'/wp-content/uploads/2013/05/kabeduvarkad-300x225.jpg<br>'
)
)
)
);
// Helper function
function getFiles($data, &$fileList) {
foreach ($data as $dataItem) {
if (is_array($dataItem))
getFiles($dataItem, $fileList);
else
$fileList[] = $dataItem;
}
}
// Debug
echo "<b>Orignal Array</b>";
var_dump($data);
echo "<hr>";
// Helper function usage
echo "<b>Parsed Array</b>";
$fileList = array();
getFiles($data, $fileList);
var_dump($fileList);
?>
Output:
Ok use this function its working
$all=array();
$it = new RecursiveIteratorIterator(new RecursiveArrayIterator($array));
foreach($it as $v) {
$all[]=$v;
}
print_r($all);
With $var[] = you basically say that you want to add a new Element to $var with an incremented key.
Your Recursive frunction returns an array.
So this array is assigned as a new element in your array.
But what you want is a flat array.
Instead of adding an array to your array like this:
if (is_array($v)){
$result[] = listArrayRecursive($v, $ident.'/'.$k);
Merge the existing arrays like this:
if (is_array($v)){
$tmpResult = listArrayRecursive($v, $ident.'/'.$k);
$result = array_merge($result, $tmpResult);
You can see a working example here.