Jump to content

empty array?


wannabe_god

Recommended Posts

how can I check if array[$i] is empty?To use like thisCodeif array[$i] != empty //how to check that it is empty{$i++; //lets do next...echo "array position " . $i . " is filled with " . array[$i] . "<br>";}EDITanother question that will solve the problem:how to find the length of an array?

Link to comment
Share on other sites

Here is the valid code in syntax... but I didn't know you can have empty arrays. (no wonder, I just got my PWS support PHP) :)

for($i = 0; $i <= SomeFunctionThatTellsTheCellAmount; ++$i){if($arr[$i] != "") // check that it is empty{$i++; // lets do next...echo "array position " . $i . "is filled with " . array[$i] . " <br />";}}

I dunno does this work but have a try.

Link to comment
Share on other sites

I don't really see what you added apart of a for loop who doesn't help me mutch becouse I did not have a function to tell the cellamount.However, I just found out, (well, I asked someone...) that count($input) counts the fields of the array. Thanks for trying to help, though.this works...

for($i=0;$i<count($input);$i++)    echo $i+1 . ": " . $input[$i] . "<br>";

Link to comment
Share on other sites

Then it should be like:

foreach($array as $val){if (empty($array)) // check that it is not empty{echo "array position " . $i . "is filled with " . array[$i] . " <br />";}}

Link to comment
Share on other sites

Then it should be like:
foreach($array as $val){if (empty($array)) // check that it is not empty{echo "array position " . $i . "is filled with " . array[$i] . " <br />";}}

If the $array is empty nothing inside the forech loop will get executed.
Link to comment
Share on other sites

Then it should be like:
foreach($array as $val){if (empty($array)) // check that it is not empty{echo "array position " . $i . "is filled with " . array[$i] . " <br />";}}

$i is also undefined. You were probably thinking of this:
foreach($array as $key => $val){  echo "array position " . $key . "is filled with " . $val . " <br />";}

In that case you don't even need to check if it is empty, because you are iterating through each element. The foreach loop will not execute if the array is empty.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...