PHP上移echo以填满空白区域

How should i do to populate array results into a box. And it should continue to move up to fill the empty space with subsequent search if earlier search resulted in null. And if earlier search is not empty, the subsequent search will be populated in its own position accordingly.

Box
Result 1 // Search on $Arr1 for 'X'
Result 2 // Search on $Arr2 for 'X'. Move up if Result 1 is empty
Result 3 // Search on $Arr3 for 'X'. Move up if Result 1 or 2 is empty

I tried the following code, but it either doesnt move up to fill the empty space if earlier search was empty nor can it fill up accordingly if more than one result is not empty.

<?php

    if (($pos1 = array_search('X', $Arr1, true)) !=== null){
    echo $pos1; ?><br />
    <? 
} else {
  if (($pos2 = array_search('X', $Arr2, true)) !=== null){
            echo $pos2; ?><br /> 
            <?
    } else {
      if (($pos3 = array_search('X', $Arr3, true)) !=== null){
            echo $pos3; ?>
    }

  ?>

I'm not sure if I understand it well, but you could try the ternary operator:

<?php

    echo array_search('X', $Arr1, true)
         ?: array_search('X', $Arr2, true)
         ?: array_search('X', $Arr3, true)
         ?: 'default_value';

?>

try this :

<?php

if (($pos1 = array_search('X', $Arr1, true)) !== null)
    echo $pos1."<br />";
else if (($pos2 = array_search('X', $Arr2, true)) !== null)
    echo $pos2."<br />"; 
else if (($pos3 = array_search('X', $Arr3, true)) !== null)
    echo $pos3;

?>