将数组转换为字符串转换错误:$ sub = $ foldername。'/'。$ check [$ x];。 请指教

I am new to PHP. Here i am trying to create Parent Folder and Sub folder based on the input from a form. I am Getting Array to string conversion error at the line : $sub= $foldername.'/'.$check[$x];. Please advice.

//Creating the parent and sub folder
$checked_count1=5;
$foldername = $_POST['foldername'];
       $structure = dirname(__FILE__).DIRECTORY_SEPARATOR.$foldername;

      if (!mkdir($structure, 0777, true)) {
        die('Failed to create folders...');
      }
   //Subfolder
   for($x=0;$x<$checked_count1;$x++)
   {
   $sub= $foldername.'/'.$check[$x];
   if(!file_exists($sub)){
   mkdir($sub, 0777);
   }
   }

Even though $check is not set in the given code, php prpbably thinks the value of $check[$x] is an array. Also you're concatenating this array to a string, hence the array to string conversion error. Only strings can be concatenated. When possible, php converts other type values to a string first. This is not possible for an array.