Jump to content

How To Output A A Html Line If Array Element Is Not Blank


kevinkhan

Recommended Posts

I have an array like this

 

Array
(
   [0] => Array
    (
	    [id] => 139
	    [name] => Eithne Maun
	    [contactNo] => 877692398
	    [email] => [email protected]
	    [address] =>
	    [county] => Cork
	    [country] => Ireland
	    [sourceOfContact] => Phone
	    [type] => Corporate
	    [dateAdded] => 2012-11-26
	    [companyName] =>
	    [dateOfBirth] =>
    )

)

 

I want to loop through each element in the array and only display the lines below if the value is not blank

Number: <?php htmlout($contact[0]['contactNo']);?><br />
	        Email: <?php htmlout($contact[0]['email']);?><br />
		    Address: <?php htmlout($contact[0]['address']);?><br />
		    County: <?php htmlout($contact[0]['county']);?><br />
		    Country: <?php htmlout($contact[0]['country']);?><br />
		    Type of Contact: <?php htmlout($contact[0]['type']);?><br />
		    Company Name: <?php htmlout($contact[0]['companyName']);?><br />
		    Date of Birth: <?php htmlout($contact[0]['dateOfBirth']);?><br />

 

Is there a function with a loop that i could use??

$arr = array (
0 => array (
	'id' => 139,
	'name' => 'Eithne Maun',
	'contactNo' => '877692398',
	'email' => '[email protected]',
	'address' => '',
	'county' => 'Cork',
	'country' => 'Ireland',
	'sourceOfContact' => 'Phone',
	'type' => 'Corporate',
	'dateAdded' => '2012-11-26',
	'companyName' => '',
	'dateOfBirth' => ''
)
);

foreach ($arr[0] as $k => $v) {
if (empty($v)) {
	continue;
}
echo $k .' - '. $v .'<br/>';
}

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.