Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8057595
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T09:04:58+00:00 2026-06-05T09:04:58+00:00

I am pretty green when it comes to php, so here’s a basic question

  • 0

I am pretty green when it comes to php, so here’s a basic question for which I have not found an answer yet.

I extract repetitive information from a page by doing regex matching as follows. The regex has two capturing groups (…), hence the $matches array has index ranging from 0 (full regex value) to 2 ( 1 and 2 are the capturing group values).

<?php
    $page = file_get_contents(url);
    preg_match_all(regex-with-two-capturing-groups, $page, $matches);
    $m1 = $matches[1];
    $m2 = $matches[2];
    for ($i=0; $i < sizeof($m1); $i++) {
        echo ("<tr><td>$m1[$i]</td><td>$m2[$i]</td></tr>");
    }
?>

This works fine, but at first I tried a shorter version:

<?php
    $page = file_get_contents(url);
    preg_match_all(regex-with-two-capturing-groups, $page, $matches);
    for ($i=0; $i < sizeof($matches[0]); $i++) {
        echo ("<tr><td>$matches[1][$i]</td><td>$matches[2][$i]</td></tr>");
    }
?>

but this resulted in

<tr><td>Array[0]</td><td>Array[0]</td></tr>
<tr><td>Array[1]</td><td>Array[1]</td></tr>
<tr><td>Array[2]</td><td>Array[2]</td></tr>
<tr><td>Array[3]</td><td>Array[3]</td></tr>
<tr><td>Array[4]</td><td>Array[4]</td></tr>
...

Why is this?
And is there a way to do two-dimensional indexing in one expression, not having to define intermediate arrays m1 and m2?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-05T09:05:00+00:00Added an answer on June 5, 2026 at 9:05 am

    Use this code:

    <?php
        $page = file_get_contents(url);
        preg_match_all(regex-with-two-capturing-groups, $page, $matches);
        for ($i=0; $i < sizeof($matches[0]); $i++) {
            echo ("<tr><td>".$matches[1][$i]."</td><td>".$matches[2][$i]."</td></tr>");
        }
    ?>
    

    PHP Documentation : language.types.string.parsing

    Look also here : PHP: concatenation of multidimensional array elements

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Pretty simple question. I have a few ASP RequiredFieldValdators checking some text boxes. Out
Pretty basic question, I know... I just don't know how it's done. I want
I'm pretty green when it comes to WPF, so forgive me if this is
I should start of by saying that I'm still pretty green when it comes
I am still pretty green when it comes to web development and javascript/jQuery programming,
I have a standard data-entry type form built in ASP.NET. I am pretty green
This should be pretty basic but i can't figure it out. Have a table
I'm pretty green still when it comes to web programming, I've spent most of
Still pretty green on clojure, java, layouts etc. On a miglayout I have this
Pretty much the same as this question. But I can't seem to get this

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.