Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

foreach with single element

Status
Not open for further replies.

nemini

Programmer
Sep 22, 2008
21
US
On a few hundred of lines I call a foreach quite a few times
(Checking img file)
It works fine in a multiple files environment
But if the user enters only one element then the foreach runs one too many time and adds an empty element
How could I go around that problem, do I have to set a switch and check for values in order to serve a foreach or a non-foreach snippet?
 
I found my error
The rest of the script is under the influence of
a quantity that I got from $aaa=$_FILES[‘image_file’]
which was reading all components of the file (5) although I was passing only one img
Not a good idea to do as I did!
Be sure (if testing for a quantity) to check for only a single value
For ex: $aaa=$_FILES[‘image_file’][‘file_name’]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top