How to merge the values of an array into multidimensional array?

sorry for the title of my question i really don't know how to emphasize my problem but here is the sample array:

enter image description here

and here is my code

foreach ($_POST['noofguest'] as $keyg => $valueg) {

                echo $valueg. "<br />"; 

}

        foreach($_POST['room_no'] as $key => $value){

            foreach($value as $key2 => $value2){

                echo $value2 . " has " . $valueg . "<br />";
            }


        }

and the result of this is:

1

2

56 has 1

57 has 1

but this is not the result that i want, what i want is

1

2

56 has 1

57 has 2

is this possible??

Upvotes: 0

Views: 22

Answers (1)

uri2x
uri2x

Reputation: 3202

For the second loop, you want to receive the same index of the room_no but only inside the noofguest array. So that's exactly what you should do:

foreach($_POST['room_no'] as $key => $value)
  foreach($value as $key2 => $value2)
    echo $value2 . " has " . $_POST['noofguest'][$key2] . "<br />";

Upvotes: 1

Related Questions