Move "$num=0" to line before "$itemnum = array($num)"