Remove a blank element from array- How?

ok, guys, this SHOULD be easy, right? In an old HTML guy, and getting better at this, but this seems like it should have been a set PHP funtion...

I post variables via form on previous page and its assigned to $arrayname (that all works), and if the blank element falls to end or beginning, we could pop it off...but what if the blank "" string (which it is, i tested and it comes back string) is in the middle of the array. All I want to do is remove blank entries before further manipulating the array into display and saved contents.

PLEASE! anybody! help! LOL! I have searched everywhere!

<pre>
$array=$arrayname;
$cnt=count($array);
for($i=0; $i<$cnt; $i++){
echo "<tr><td width=100>".$array[$i]."</td></tr>\n";
echo gettype($array[$i]);
}
$parsed=$array;
</pre>

    I'm not entirely sure what you're tryng to do, but take a look at this code it might be helpful....

    foreach( $arrayname as $aKey => $aValue)
    {

    if(!empty($aValue))
    {
    	$var_name = $aKey;
    	$$var_name = $aValue;
    	echo "$aKey = $aValue <br>";
    };

    };

    I think this might be useful to you, it should work, though I did just edit it down to illustrate the idea. It should display only the filled values in the array, and their key names. Substitute the echo command with other instructions, but you knew that already.

    Good Luck,
    -Haji

      close, i had a very similar set of expressions working that angle last night. but the important part is that I want to remove the empty keys (on unset them) and then save the array into a new array ONLY populated by keys/values with a non-blank value.

      Ill give it a shot though.

      Haji Hill wrote:

      I'm not entirely sure what you're tryng to do, but take a look at this code it might be helpful....

      foreach( $arrayname as $aKey => $aValue)
      {

      if(!empty($aValue))
      {
      	$var_name = $aKey;
      	$$var_name = $aValue;
      	echo "$aKey = $aValue ";
      };

      };

      I think this might be useful to you, it should work, though I did just edit it down to illustrate the idea. It should display only the filled values in the array, and their key names. Substitute the echo command with other instructions, but you knew that already.

      Good Luck,
      -Haji

        err, i should have said "REMOVE the empty key/value pairs, and not unset() them

        unset() only changes the empty value and sets it to NULL. I tested that last night.

          bump, still looking for the answer, help!

            bump, still looking for the answer.

            Haji, that DID work for removing the key/value pairs that were "empty" but only for the duration of the call. Once, the next line of code continues, the array still contains the empty key/value pairs.

            Perhaps I should somehow write those into a new array?...hmmm. ill work that and see if it works.

            meanwhile, call still stands....

            how to permanently remove an "empty" ie, sting is "" blank from a form submission from an array.

            TIA

              Write a Reply...