Fix key and value issue for looping array