unset Versus Wiping an Array
As @'oguz ismail' mentioned, the OP can either use the unset command or wipe the array (empty it).
There are important nuances between the two methods.
unset completely removes the array and its structure (type of array, all its keys, all values) from memory. The array no longer exists. If one wants to use it again, then one would need to declare it again.
versus
myArray=() retains the array type (indexed or associative), but wipes out all keys and values. The array itself continues to exist.
When to Use Either Method
This is where things get nuanced.
Pros and Cons of Unset
If your needs are basic; let's say you want to wipe the contents of an array in a script, and the array and its content will never be needed after that point. Well, then you might as well use unset IMHO, though you could use either. Technically, unset is the superior choice because it releases the memory back to the kernel. But for most applications, it really doesn't matter unless your array is very large.
Where the OP may run into problems is when downstream in the script, certain commands that are looking for the array or one of its elements (keys). Which commands? Any line that requires the array or one of its elements to be actioned somehow.
For example, a command such as this: if [ -n "${my_array[$key]}" ]; then ... will work just fine and will not complain if the array doesn't exist or the element $key doesn't exist. The test will fail, and the script will move on. No errors. No complaining from the SHell.
However, in the OP's scenario they clearly had some sort of command on line 49 that does expect the array to exist, as you wrote:
So I used unset to empty the array but it's giving error.
line 49: unset: x': not a valid identifier`
Pros and Cons of Wiping the Array
Alternatively, wiping the array causes the contents of the array to be wiped out (its keys and their values), while retaining the array definition itself.
So, in the OP's scenario you'd possibly want to go this route in order to avoid the error you encountered on line 49. However, this would not necessarily solve your error message issue. It would depend on what caused the error. Since the OP did not share the entire script, it's not clear whether this approach would make a difference or not.
The bottom line is the upside of this approach (wiping the array, but leaving its structure intact) will not cause commands to fail that check for or require the presence of the array, though this comes at the expense of increased memory utilization (potentially a waste).