Sort array that brings all the elements in another array and classify the values

0

I do not see any way of asking it in a technical way, so I will be supported with images. I have an array which I get in a request in Laravel 5.6 that contains the following values:

The idea is to pass them to another array so that they remain like this:

That is to say

Edit1: Initially the array arrives to me in the following way:

Use a foreach to take all the values and store them in the array of the first image.

The code used to convert the array to the last image as it is in the first image.

foreach($fpagos as $fpago){
        foreach($fpago as $dpago){
            //dd($dpago);
            $pagos_n[] = $dpago['name']; 
            $pagos_n[] = $dpago['value'];
        } 
    }

Edit2: Try using the code you passed me, I think I used it wrong because I throw the same array without changes

foreach ($pagos_n as $key => $value){
        $pagos_n[$key];
    }
    
asked by Kinafune 23.08.2018 в 19:01
source

2 answers

0

Try this

<?php

$data=array("t_pago","Efectivo","monto","123","t_pago","Deposito","monto","1234");

foreach ($data as $key => $value) 
{
    echo $data[$key];
}

? >

    
answered by 23.08.2018 в 19:12
0

You could do it this way:

foreach($fpagos as $fpago){
   foreach($fpagos as $dpago){
        foreach($dpago as $key => $value){ 
            $pagos_n[] = $value;
        }
    }
}
    
answered by 24.08.2018 в 05:12