未定义的偏移:2使用php中的preg_split

I am currently developing a system. I have tab menu in user, in here all the menus will be display. I have module called add menu where the admin will add another menu, after creating a new menu it will be added to the tab menu of the user. I have given menus like Sizzling Plate and Tacos, the things that I've done is when the user click the Sizzling Plate it will redirect you to that menu

Like this: localhost:/xxxx/SizzlingPlate. Then it will display the information of the Sizzling Plate

Example: Name:

SizzlingPlate
Price:  50
Stocks: 5

So in here I used the preg_split to separate the 2 capital letter to have a space so in will become like this one

Example:

Name:   Sizzling Plate
Pirce:  50
Stocks: 5  

But Im encountering error Undefined offset: 2 when the added menu is just 1 word like tacos.

NOTE: Im retrieving all the datas in my menu table. My example data is SizzlingPlate. I also tried to put condition for both order page and in my controller still getting the undefined offset: 2

if($pieces[2] != '')
{
    $concat = $pieces[1] . " " .    $pieces[2];

}
else
{
    $concat = $pieces[0] . " " .    $pieces[1];
}

Question: How can I fix it?

Menu

<div class="row">
    <div class="col-md-1"></div>
    <div class="col-md-10" style="padding-left: 0px; padding-right: 0px;">
        <?php foreach($menu as $row):?>
        <img src="<?= base_url().'uploads/'.$row->menu_image?>" style="max-width: 33%">
        <?php $name = $row->menu_name; 
            $remove_space = strtolower(str_replace(' ', '', $name));?>
        <a href="order/<?= $name?>"><button class="btn btn-primary btn-md">Order Now </button></a>
        <?php endforeach;?>
    </div>
    <div class="col-md-1"></div>
</div>

When user click that menu

<?php $order_name = $name->menu_name;
                    $pieces = preg_split('/(?=[A-Z])/',$order_name);

                        $concat = $pieces[1] . " " .    $pieces[2];


                    var_dump($concat);
                    if($concat == $concat){?>

                    <div class="form-group">
                        <input type="text" disabled="" name="name" id="name" value="<?= $concat?>"">
                        <input type="hidden"  name="name" id="name" value="<?= $concat?>">
                    </div>
                <?php }?>

Controller

public function order($name)
    {
        $pieces = preg_split('/(?=[A-Z])/',$name);
                    $concat = $pieces[1] . $pieces[2];
        $where = array('menu_name' => $name);

        $get_name = $this->Crud_model->fetch_tag_row('*','menu',$where);
        parent::mainpage_order('users/order',
                [
                    'title'         =>'Order' ,
                    'name'          => $get_name
                ]
        );
    }

Edited

Question:What if I want to display it back to the original?

I've done this but it didn't work.

$uppercase_menu_name = $this->input->post('menu_name');

            $pieces = preg_replace('/(.)(?=[a-Z])/u', '$1', $uppercase_menu_name);

If you just want to add a space between the two words, you could use preg_replace instead.

preg_replace('/(.)(?=[A-Z])/u', '$1 ', $name);
// Taco -> Taco
// SizzlingPlate -> Sizzling Plate

I grabbed this example from the Laravel source code: https://github.com/laravel/framework/blob/5.5/src/Illuminate/Support/Str.php#L453