Jump to content

How To Show The Results Of An Array


manalnor

Recommended Posts

Hello dear friends,

 

If i've the following array results then how i can show it up !

 

 

 

array code

$urlByHost = array();
foreach (explode("\n", $_POST['url']) as $value) {
   $parse = parse_url($value);
   $urlByHost[$parse['host']][] = array(
       'url' => $value,
       'parse' => $parse,
       'md5' => md5($value),
   );
}
asort($urlByHost);

print_r($urlByHost);

 

 

results

Array
(
   [www.bing.com] => Array
       (
           [0] => Array
               (
                   [url] => http://www.bing.com/kee
                   [parse] => Array
                       (
                           [scheme] => http
                           [host] => www.bing.com
                           [path] => /kee_
                       )

                   [md5] => e69d3a5bb987448e30ec8559c3634caf
               )

       )

 

i want to show the host and md5 as

 

www.bing.com

e69d3a5bb987448e30ec8559c3634caf

 

 

how can i call the results and show it ! ~ thanks

Link to comment
https://forums.phpfreaks.com/topic/268990-how-to-show-the-results-of-an-array/
Share on other sites

Example,

$arrInfo = array(
'www.bind.com' => array(
0 =>array(
 'url' => 'http://www.bing.com/kee',
 'parse' => array(
 'schame' => 'http',
 'host' => 'www.bing.com',
 'path' => '/kee_'
 ),
 'md5' => 'e69d3a5bb987448e30ec8559c3634caf'
 )
)
);
echo $arrInfo['www.bind.com'][0]['parse']['host'].'<br />'; // www.bing.com
echo $arrInfo['www.bind.com'][0]['md5']; // e69d3a5bb987448e30ec8559c3634caf

The above example won't work if your array is dynamically generated, which by looking at your previous code, it is.

 

Luckily, not all of the array is dynamic which makes this process a little easier, try the following:

 


$urlByHost = array ( );
foreach ( explode ( "\n", $_POST [ 'url' ] ) as $value )
{
   $parse = parse_url ( $value );
   $urlByHost [ $parse [ 'host' ] ] [ ] = array (
       'url' => $value,
       'parse' => $parse,
       'md5' => md5 ($value ),
   );
}
asort ( $urlByHost );

foreach ( $urlByHost as $key => $value )
{
   foreach ( $value as $v )
   {
       echo $v [ 'parse' ] [ 'host' ] . '<br />' . $v [ 'md5' ];
   } 
}

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.