Is the additional variable $k necessary? Would it be possible to create a $component and after setting it up append it to the $components array?