Go Back   CodingForums.com > :: Server side development > PHP

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 11-28-2012, 04:44 PM   PM User | #1
kevinkhan
Regular Coder

 
Join Date: Jun 2009
Posts: 350
Thanks: 75
Thanked 0 Times in 0 Posts
kevinkhan is an unknown quantity at this point
Looping through array and seeing which values are empty

I have an array like this

PHP Code:
Array
(
    [
0] => Array
        (
            [
id] => 139
            
[name] => Eithne Maun
            
[contactNo] => 877692398
            
[email] => eithne@yahoo.co.uk
            
[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
PHP Code:
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??
kevinkhan is offline   Reply With Quote
Old 11-28-2012, 05:34 PM   PM User | #2
poyzn
Regular Coder

 
poyzn's Avatar
 
Join Date: Nov 2010
Posts: 265
Thanks: 2
Thanked 61 Times in 61 Posts
poyzn is on a distinguished road
use foreach with keys

PHP Code:
foreach($contact[0] as $key => $val) {
  echo 
"{$key} => {$val}\n";

__________________
Ushousebuilders.com
poyzn is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 04:29 AM.


Advertisement
Log in to turn off these ads.