Hi all, I have a fairly simple problem. I have an array which prints out the following text:

1
 
Full, Gen. 3
 
TMSWK2D
9
Poor write quality
2
 
Full, Gen. 1
 
TMSWK2C
 
Read Only, Clean Tape

The problem is after some of the lines of text, there are empty values, causing there to be a line break. Here is the code that prints out the values.

<table>
<?php 
	$i=0;
	while(isset($html[$i]))
	{
?>
		<tr>
			<td><?php echo $html[$i]; ?></td>
		</tr>
<?php			
		$i++;
	}
?>
</table>

I have tried these two solutions in the hope that if one evaluates to true, then the $i++ would effectively skip the blank value and continue to print the next array value, but this hasn't worked.

if($html[$i] == " ")
		{
			$i++;
		}
	
		if(empty($html[$i]))
		{
			$i++;
		}

Any help please?!

I'm getting good at solving my own problems moments after I post them

<table>
<?php 
	$i=0;
	while(isset($html[$i]))
	{
		if(strlen($html[$i] == 0))
		{
			$i++;
		}
?>
		<tr>
			<td><?php echo $html[$i]; ?></td>
		</tr>
<?php			
		$i++;
	}
?>
</table>

Just an FYI, array_filter will also do just this when not supplied with a callback function. It will remove anything that when compared as a boolean evaluates to false. More examples in the menu.

<?php

$array = array(
	'1',
	'',
	'Full, Gen. 3',
	'',
	'TMSWK2D',
	'9',
	'Poor write quality',
	'2',
	'',
	'Full, Gen. 1',
	'',
	'TMSWK2C',
	'',
	'Read Only, Clean Tape',
);

var_dump($array);
$array = array_filter($array);
var_dump($array);
array
  0 => string '1' (length=1)
  1 => string '' (length=0)
  2 => string 'Full, Gen. 3' (length=12)
  3 => string '' (length=0)
  4 => string 'TMSWK2D' (length=7)
  5 => string '9' (length=1)
  6 => string 'Poor write quality' (length=18)
  7 => string '2' (length=1)
  8 => string '' (length=0)
  9 => string 'Full, Gen. 1' (length=12)
  10 => string '' (length=0)
  11 => string 'TMSWK2C' (length=7)
  12 => string '' (length=0)
  13 => string 'Read Only, Clean Tape' (length=21)
array
  0 => string '1' (length=1)
  2 => string 'Full, Gen. 3' (length=12)
  4 => string 'TMSWK2D' (length=7)
  5 => string '9' (length=1)
  6 => string 'Poor write quality' (length=18)
  7 => string '2' (length=1)
  9 => string 'Full, Gen. 1' (length=12)
  11 => string 'TMSWK2C' (length=7)
  13 => string 'Read Only, Clean Tape' (length=21)
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.