gh Posted April 8, 2011 Share Posted April 8, 2011 Hello, I've been curious why the following won't work. Could anyone show me what I am doing wrong. The code is to find the TLD in a URL. $a[] = parse_url( 'www.example.com' ); $tld_arr = array ( 'com', 'net', etc...); for ($i=0; $i<count($this->a); $i++) { if (in_array ( $this->a[$i]['host'], $tld_arr) ) < This is what I'm curious about { //do something } // do something else } Thank you Link to comment https://forums.phpfreaks.com/topic/233035-multidimension-array-in_array/ Share on other sites More sharing options...
dcro2 Posted April 8, 2011 Share Posted April 8, 2011 The 'host' part would be something like 'example.com' or 'google.com' so you'll have to extract the tld from there first. Just an example: $a[] = parse_url('http://www.example.com'); $a[] = parse_url('http://google.com'); $tld_arr = array ( 'com', 'net', 'etc' ); foreach ($this->a as $url) { $parts = explode('.', $url['host']); if (in_array ( $parts[count($parts)-1], $tld_arr) ) { //do something } // do something else } echo "</table>\n"; Link to comment https://forums.phpfreaks.com/topic/233035-multidimension-array-in_array/#findComment-1198520 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.