Jump to content

[SOLVED] Array Combination help


Demonic

Recommended Posts

Alright I got this array right:

 

Array
(
    [0] => Array
        (
            [0] => <title>W3Schools Home Page</title>
            [1] => <title>RSS Tutorial</title>
            [2] => <title>XML Tutorial</title>
        )

    [1] => Array
        (
            [0] => W3Schools Home Page
            [1] => RSS Tutorial
            [2] => XML Tutorial
        )

    [2] => Array
        (
            [0] => <link>http://www.w3schools.com</link>
            [1] => <link>http://www.w3schools.com/rss</link>

            [2] => <link>http://www.w3schools.com/xml</link>
        )

    [3] => Array
        (
            [0] => http://www.w3schools.com
            [1] => http://www.w3schools.com/rss
            [2] => http://www.w3schools.com/xml
        )

    [4] => Array
        (
            [0] => <description>Free web building tutorials</description>
            [1] => <description>New RSS tutorial on W3Schools</description>
            [2] => <description>New XML tutorial on W3Schools</description>
        )

    [5] => Array
        (
            [0] => Free web building tutorials
            [1] => New RSS tutorial on W3Schools
            [2] => New XML tutorial on W3Schools
        )

)

 

So im trying combine them together using foreach for each section whats best way to do this?

 

I want the outcome to be as follows:

W3Schools Home Page : http://www.w3schools.com : Free web building tutorials

New RSS Tutorial : http://www.w3schools.com/rss : New RSS tutorial on W3Schools

New XML Tutorial : http://www.w3schools.com/xml : New XML tutorial on W3Schools

 

Whats best way to do this?

 

How I got that array:

 

<?php
$file = "rssfeeder-test.xml";
$size = filesize($file);
$rss = file_get_contents($file,$size);
//echo ("<textarea cols='40' rows='40'>$rss</textarea>\n");

preg_match_all("/\<title\>(.*)\<\/title\>/i",$rss,$title);
preg_match_all("/\<link\>(.*)\<\/link\>/i",$rss,$link);
preg_match_all("/\<description\>(.*)\<\/description\>/i",$rss,$desc);


$result = array_merge_recursive($title,$link,$desc);
print_r($result);
?>

 

http://www.uni-code.com/codebox/rssfeeder-test2.php

Link to comment
Share on other sites

<?php
$data = Array
(
    0 => Array
        (
            0 => '<title>W3Schools Home Page</title>',
            1 => '<title>RSS Tutorial</title>',
            2 => '<title>XML Tutorial</title>'
        ),

    1 => Array
        (
            0 => 'W3Schools Home Page',
            1 => 'RSS Tutorial',
            2 => 'XML Tutorial'
        ),

    2 => Array
        (
            0 => '<link>http://www.w3schools.com</link>',
            1 => '<link>http://www.w3schools.com/rss</link>',
            2 => '<link>http://www.w3schools.com/xml</link>'
        ),

    3 => Array
        (
            0 => 'http://www.w3schools.com',
            1 => 'http://www.w3schools.com/rss',
            2 => 'http://www.w3schools.com/xml'
        ),

    4 => Array
        (
            0 => '<description>Free web building tutorials</description>',
            1 => '<description>New RSS tutorial on W3Schools</description>',
            2 => '<description>New XML tutorial on W3Schools</description>'
        ),

    5 => Array
        (
            0 => 'Free web building tutorials',
            1 => 'New RSS tutorial on W3Schools',
            2 => 'New XML tutorial on W3Schools'
        )

);

for ($i=0; $i<3;$i++) {
    echo strip_tags($data[0][$i]), ' : ', $data[3][$i], ' : ', $data[5][$i], '<br>';
}

?> 

Link to comment
Share on other sites

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.