Search code examples
phparrayswordpressloopsfetch

how to fetch data in loop from nested array in php


i have this array available

Array ( 
[0] => Array (
     [0] => FL 
     [1] => members 
    ) 
[1] => Array (
     [0] => FK 
     [1] => members
    ) 
[2] => Array (
     [0] => number 
     [1] => number 
    ) 
[3] => Array (
      [0] => FV 
      [1] => mem 
    ) 
)

and I want to fetch this data as

 FL FK number FV
 members members number mem

I have given this data as an input field and want to show this as input too example input is given from: http://prntscr.com/1r6p4y1 and want the output as same as the input given in these fields

I have tried this code:

   foreach($project_fields as $k => $detail){
                    foreach ($detail as $key => $value) {
                         
                        echo '<li class="detail_list"> &nbsp; <label>'.(isset($detail)? $value : $value ).' &nbsp;  ';

                        echo " ".' </label>
                        <input type="hidden" name="project_fields[label][]" value="'.$value.'" />
                        <input type="hidden" name="project_fields[key][]" value="'.$custom_details[$k].'" />
                        <input type="hidden" name="project_fields[type][]" class="privacy_select" value="'.(isset($project_fields['type'][$k])?$project_fields['type'][$k]:'all').'" />
                        <input type="hidden" name="project_fields[value][]" value="'.$project_fields['value'][$k].'" />
                        <span class="dashicons dashicons-no-alt"></span></li>';
                    
                    }
                }

but it is returning this:

http://prntscr.com/1r6ppzg

i want it like:

FL FK number FV
 members members number mem

anyone can help will appreciatable


Solution

  • Since your array is multidimensional, You can store the data in 2 different arrays and again show as per your need.

    Here is example as per your output,

    foreach ($your_array as $value) {
        $array1[] = $value[0];
        $array2[] = $value[1];
    }
    echo "<pre>";
    print_r($array1) . "<br/>";
    print_r($array2) . "<br/>";