Jump to content

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

Edited by jazzman1

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' ];
   } 
}

Edited by JLT
This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.