-1

I have total 3 array

First array contains list of titles Second array contains list of description third array contains images

I have already combine 1st and 2nd array as a key of first array and value of second array and I also combine 1st and 3rd array as key of 1st and value of 3rd.

Following is my arrays

1 )

Array
(
    [First] => FFFFFFFFFFFFFFFF
    [Second] => ssss
    [0] => Array
        (
            [First] => eae2d7b3f20250def1892bae1abaf07f.png
            [Second] => ea7ca514d1ef580f85fb42c7cb425462.png
        )

)

I want output like

Array

(
    [First] => FFFFFFFFFFFFFFFF
    [Second] => ssss
    [First] => eae2d7b3f20250def1892bae1abaf07f.png
    [Second] => ea7ca514d1ef580f85fb42c7cb425462.png
)

Code

foreach ($images as $key => $value) {
            $values['image']= $value;
        }


$data = array_combine($_POST['title'], $images);


 $mainArray = array_combine($_POST['title'], $_POST['Description']);


array_push($mainArray,$data);
echo '<pre>';
print_r($mainArray);

How can I do this?

1 Answers1

0

The code below should produce the format the array as required above, although it is not the most elegant way to flatten an array. It may be worthwhile looking at previous questions like How to Flatten a Multidimensional Array?

$newArr = array();
foreach ( $mainArray as $key => $val ) {
    if ( is_array( $val ) ) {
        foreach ( $val as $key2 => $val2 ) {
            $newArr[$key2] = $val2;
        }
    } else {
        $newArr[$key] = $val;
    } 
}
gnusey
  • 354
  • 3
  • 16