Remove [] from $room_ids[] = $request->get('room_ids');. This syntax means pushing values in the next index. Thus, your $room_ids will has filled $room_ids[0] with received data and count($room_ids) will be equal to 1, but count($dates) could be more then 1, so, $room_ids[$i] will receive next $i and thus the $room_ids[1] will be undefined. Also, you're using $dates[$f] when it supposed to be $dates[$i] and also $room_ids[$i] perhaps should be $room_ids[$f]. Next step, $room_price[$i]; means that $room_price should be an array and $i is a counter of $dates array(from prev for loop), be careful with it. This means, that length of $dates should be the same as length of $room_price, which you've received from database.