fork download
  1. <?php
  2.  
  3. $array = [[
  4.  
  5. 'field_label' => [
  6. 'texto','checkbox','URL'
  7. ],
  8.  
  9. 'field_type' => [
  10. 'texto','checkbox','url'
  11. ],
  12.  
  13. 'field_value' => [
  14. '','valor_1 | Valor 1
  15. valor_2 | Valor 2',''
  16. ],
  17.  
  18. 'field_required' => [
  19. 'on','on', 'on'
  20. ],
  21.  
  22. 'field_order' => [
  23. '1','2','3'
  24. ]
  25.  
  26. ]];
  27.  
  28. $newArray = [];
  29.  
  30. $maxKeys = count(max($array[0]));
  31.  
  32. for($x = 0; $x < $maxKeys; $x++){
  33. foreach ($array[0] as $key => $arr){
  34. if(isset($arr[$x])){
  35. $newArray[$x][$key] = $arr[$x];
  36. } else {
  37. $newArray[$x][$key] = "";
  38. }
  39.  
  40. }
  41. }
  42.  
  43. print_r($newArray);
Success #stdin #stdout 0.02s 23680KB
stdin
Standard input is empty
stdout
Array
(
    [0] => Array
        (
            [field_label] => texto
            [field_type] => texto
            [field_value] => 
            [field_required] => on
            [field_order] => 1
        )

    [1] => Array
        (
            [field_label] => checkbox
            [field_type] => checkbox
            [field_value] => valor_1 | Valor 1
    valor_2 | Valor 2
            [field_required] => on
            [field_order] => 2
        )

    [2] => Array
        (
            [field_label] => URL
            [field_type] => url
            [field_value] => 
            [field_required] => on
            [field_order] => 3
        )

)