The essence of the question is the following - there is an array obtained by means of explode . This array can contain from 1 to 5 elements. Everything flies from space, i.e. unknown values. It is necessary to do the following - to collect a multidimensional associative array on the fly, for example:
array(2) { [0]=> string(12) "Голова" [1]=> string(8) "Глаз" } How to get:
array(1) { ["Голова"]=> array(1) { ["Глаз"]=> array(0) { } } } Most likely, at the next iteration of the cycle the string "Head Ear" will arrive, in the end it should turn out:
array(1) { ["Голова"]=> array(2) { ["Глаз"]=> array(0) { } ["Ухо"]=> array(0) { } } } Share your advice or uncomplicated code.