Dynamic insertion of elements into the array without enforcing a specific order

I have 3 input requests which is

$inputValues = array(
   'communication_text' => $request->text,
   'mms_image' => $request->mms_image,
   'communication_text2' => $request->text2
);

I want to insert the data inside into the following array:

$messageSegments = array();

foreach ($inputValues as $inputName => $inputValue) {
            // Check if the input value is not empty
    if (!empty($inputValue)) {
                // Add message segment based on input type
          if ($inputName === 'mms_image') {
              $messageSegments[] = array(
              "contentId" => basename($inputValue),
              "contentType" => "image/jpeg",
              "contentUrl" => $inputValue
             );
          } else {
             $messageSegments[] = array("text" => $inputValue);
          }
      }
   }

It always inside the data in specific order into $messageSegments array. How can I make it dynamic means if mms_image comes first , communication_text2 comes second, $messageSegments array should also be in that order as my form element is a draggable. User can change $request by dragging and $messageSegments array content also in that order?