PHP在单个结果时显示字符串的第一个字符,但在多个结果时显示完整字符串

So the problem that I am encountering is that I have a select field that is populated via PHP. A MySQL DB is queried and the PHP processes the returned array, printing it into the select field's options.

However, when a single result is returned from the DB, only the first character of the string is displayed. If multiple results are returned, then all results display fully. I have checked that when a single result is returned, that the string itself is correct, which it is, so I don't believe this to be an issue with the data retrieval. Furthermore, no errors are generated either, so no clues are provided as to where things are going wrong.

I've tried to find other StackOverflow posts describing this issue, but haven't found anything, nor can I find anything elsewhere on the internet.

This is the DB Stored Procedure that collects the results:

BEGIN
SELECT BranchID, City FROM Branch;
END

Then this PHP turns that data into an associative array:

$result = $currentconnection->DBQuery("CALL Fetch_Branch_City_All()");
        if( !$result) die($mysql->error);
        while($row = $result->fetch_assoc()){
            $BranchID = $row["BranchID"];
            $CityName = $row["City"];
            $results = $this->array_push_assoc($results, 'BranchID', $BranchID);
            $results = $this->array_push_assoc($results, 'CityName', $CityName);
        }

This is a go-between piece of code that calls the function above and makes it available to the code below, via the $Query variable.

$Query = $pModel->fetchBranchCity();

And finally this code creates the select from the array data:

<?php //Note if only one branch in system, displays single character
                extract($Query, EXTR_OVERWRITE);

                for ($a = 0; $a < count($BranchID); ++$a) {
                    if($BranchID[$a] == $BranchIDText){ ?>
                        <option value="<?=$BranchID[$a]?>" selected="selected"> <?=$CityName[$a]?> </option>
                    <?php }else{ ?>
                        <option value="<?=$BranchID[$a]?>"> <?=$CityName[$a]?> </option> 
                    <?php }
                }
                ?>

It has to do with the extract, while the $result is always an array, the $BranchID and $CityName aren't always.

So when they have one value, they aren't arrays, just strings and looping through them extracts the characters instead of the whole string from an array.

Please do tell me if you need help handling this exception in code.

hints: is_array