Plxply Posted April 14, 2010 Share Posted April 14, 2010 Hello, I currently have a script that simply runs dns_get_record against a domain which the user enters through a GET, however at the current time to display the information I am running through a large amount of if(isset()) statements so it only echo's if it's actually there. I have looked at using for each however, I seem to be unable to achieve it myself due to the slight complexity of the array. $domain = filter_input(INPUT_GET, 'domain', FILTER_SANITIZE_URL); $result = dns_get_record($domain); echo $result['0']['host']."\n\n"; if (isset($result['0'])) { echo $result['0']['type']." - ".$result['0']['target']." (TTL:".$result['0']['ttl'].")\n"; } if (isset($result['1'])) { echo $result['1']['type']." - ".$result['1']['target']." (TTL:".$result['1']['ttl'].")\n"; } As you can assume it would have to continue on in that fashion indefinitely is there an easy way to accomplish this with a for each statement and if so could you provide an example? Sorry for the rather simple question, Link to comment https://forums.phpfreaks.com/topic/198555-echo-array/ Share on other sites More sharing options...
aeroswat Posted April 14, 2010 Share Posted April 14, 2010 Do you mean this? foreach($result as $r) { echo $r['type']." - ".$r['target']." (TTL:".$r['ttl'].")\n"; } Link to comment https://forums.phpfreaks.com/topic/198555-echo-array/#findComment-1041920 Share on other sites More sharing options...
Plxply Posted April 14, 2010 Author Share Posted April 14, 2010 Thank you ever so much for your prompt and excellent answer Link to comment https://forums.phpfreaks.com/topic/198555-echo-array/#findComment-1041942 Share on other sites More sharing options...
aeroswat Posted April 14, 2010 Share Posted April 14, 2010 Thank you ever so much for your prompt and excellent answer Np good luck Link to comment https://forums.phpfreaks.com/topic/198555-echo-array/#findComment-1041952 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.