在php多维中格式化单个结果以匹配?

I'm grabbing a some XML data and parsing it with PHP.

Most of the results come in multidimensional array but occasionally I'll get a result in a single array and it breaks my script.

I'm trying to format the single result to match the format of the results in the multidiminsonal array but I'm not having any luck.

Here is what I got:

    Array
    (
                [name] => Steve Jobs
                [id] => 3
    )

Array
    (
        [0] => Array
            (
                [name] => Steve Jobs
                [id] => 6
            )

        [1] => Array
            (
                [name] => Bill Gates
                [id] => 8
            )

    )

I'm trying to format the single result to match the multidimensional format then flatten...

Array
    (
        [0] => Array
            (
                [name] => Steve Jobs
                [id] => 3
            )

        [1] => Array
            (
                [name] => Steve Jobs
                [id] => 6
            )

        [2] => Array
            (
                [name] => Bill Gates
                [id] => 8
            )

    )

I've tried this:

$array_check = @array_keys($result[0]['name']);

if ($array_check[0] == "0") {
            $result;

        } elseif ($array_check[0] == "name") {
            $ReWrite =  array ([0] =>
                        array (['name']=>
                        array ($result[0]['name'])
                        ));

            $result = $ReWrite;

        }

I thought that would do it but it's off...

Try this:

    $array_check = @array_keys($result[0]['name']);

    if (!isset($array_check[0])) {
        $result[] = $array_check;
    } else {
        $result = $array_check;
    }

    var_dump($result);

If your first array was assigned to the variable $singleArray and your target results stored in $results, try this array_push($results, $singleArray);

Use this together with reset() it returns the first element of an array:

if(!is_array(reset($result))){
    array_push($results, $result);
}

This will test if the array does not contain an array as an element, if it doesn't push the whole array to an aggregate array.

Edit: Try this loop:

for($i = 0; $i <= count($multi); $i++){
    $arr = $multi[$i];
    if(!is_array($arr)){
        $multi[$i] = array($arr);
    }
} var_dump($multi);