-2

スクレイピングスクリプトを作成したところ、うまくいきました。今、私はこの出力を取得します:

Array
(
    [0] => Array
        (
            [0] => example stuff
            [1] => example stuff
            [2] => example stuff
            [3] => example stuff
        )

[1] => Array
    (
        [0] => /spellen/thumbs/a/aladdinwildride_6524.jpg
        [1] => /spellen/thumbs/t/toystory3_3476.jpg
        [2] => /spellen/thumbs/f/fred-flintstone-bobsled_2180.jpg
        [3] => /spellen/thumbs/m/madagascar-2.jpg
    )

[2] => Array
    (
        [0] => spel Alladin Wide Rit
        [1] => spel Toy Story 3
        [2] => spel Bedrock Bobsledding blowout
        [3] => spel Madagascar 2 Ontsnap naar Afrika

    )

[3] => Array
    (
        [0] => /spellen/cartoons/2096/alladin-wide-rit.html
        [1] => /spellen/cartoons/1989/toy-story-3.html
        [2] => /spellen/cartoons/1362/bedrock-bobsledding-blowout.html
        [3] => /spellen/cartoons/237/madagascar-2-ontsnap-naar-afrika.html

    )

[4] => Array
    (
        [0] => l
        [1] => l
        [2] => l
        [3] => l

    )

[5] => Array
    (
        [0] => Speel Alladin Wide Rit online
        [1] => Speel Toy Story 3 online
        [2] => Speel Bedrock Bobsledding blowout online
        [3] => Speel Madagascar 2 Ontsnap naar Afrika online

    )

[6] => Array
    (
        [0] => e
        [1] => e
        [2] => e
        [3] => e

    )

[7] => Array
    (
        [0] => /images/thumb_frame_top.gif
        [1] => /images/thumb_frame_top.gif
        [2] => /images/thumb_frame_top.gif
        [3] => /images/thumb_frame_top.gif

    )

[8] => Array
    (
        [0] => f
        [1] => f
        [2] => f
        [3] => f

    )

)

今、foreach私はそれぞれを返す単純なものが欲しいです$matches[1][0]$matches[2][0]そして$matches[3][0]

私は何時間もこれを手に入れようとしてきましたが、運がありません. 誰でも私を助けることができますか?

4

5 に答える 5

0
$result = array();
foreach ($matches as $match) {
    $result[] = array(
        $match[1],
        $match[2],
        $match[3],
    );
    // or unset($match[0]); if you don't need the original array anymore
    // or array_splice($match, 0, 1); if you also want to rearrange the keys
}
于 2012-11-29T14:28:36.697 に答える
0
foreach($matches as $match){

    // $match[0] is what you need

}

結果を新しい配列にラップする場合は、元の配列を次のように減らすことができます。

$newArray = array_reduce($matches, function(&$result, $match){

  $result[] = $match[0];

});
于 2012-11-29T14:29:09.850 に答える
0

これはあなたが望むものですか?

for ($i = 0; $i < count($matches); $i++)
{
    print $matches[$i][0];
}
于 2012-11-29T14:30:40.793 に答える
0
foreach ($matches as $j => $match) {
   foreach ($match as $i => $mi) {
       if ($i != 0) unset($matches[$j][$i]);
   }
}
于 2012-11-29T14:35:57.507 に答える
0

最初の 3 つだけが必要な場合:

$newArray = array(
    $matches[1][0],
    $matches[2][0],
    $matches[3][0]
);

結果:

    Array
    (
        [0] => /spellen/thumbs/a/aladdinwildride_6524.jpg
        [1] => spel Alladin Wide Rit
        [2] => /spellen/cartoons/2096/alladin-wide-rit.html
    )
于 2012-11-29T14:37:21.873 に答える