You are initializing x to 0. Then executing echo once with x in this state. x then increments to 1. 1 is still less than or equal to 2, so the echo runs again. x increments again to 2, which is still less than or equal to 2, so the echo executes a third time. What you probably want to do is replace $x<=count($outlet) with $x<count($outlet), as you really want 'less than', not 'less than or equal to' for running a loop once for each index in a zero-indexed array.