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 8861765
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T15:33:53+00:00 2026-06-14T15:33:53+00:00

I have the following as a result of a preg_match_all Array ( [0] =>

  • 0

I have the following as a result of a preg_match_all

Array ( [0] => Array ( [0] => $9.70 [1] => $10 [2] => $11.95 [3] => $0.49 [4] => $2.95 [5] => $2.95 [6] => $2.95 [7] => $2.95 [8] => $0.49 [9] => $9.70 ) ) 

I’m trying to print them all in a foreach loop but getting only first character.

Here’s what I’m trying:

$i = '0';

foreach ($matches[0] as $val) {
    echo $val[$i].'<br />';
    $i++;
}

Where am I going wrong?

  • 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-14T15:33:55+00:00Added an answer on June 14, 2026 at 3:33 pm

    In PHP foreach works a different way than you think. Let me explain this using the following code:

    $matches = array('One', 'Two', 'Three');
    foreach ($matches as $value) {
        // The following code is called once for every array item, and $value is set to that array item
        echo $value . '<br />';
    }
    

    This code gives the following output:

    One
    Two
    Three
    

    This happens because the foreach body is called once for every array item, and $value is set to the value of that array item. Using your code one only sees the first character, because PHP allows you to get a single character from a string using array syntax. Long story short, change your code to the following:

    foreach ($matches[0] as $val) {
        echo $val . '<br />';
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a following structered DOM result, getting after a POST event: <root> <config>
I have the following result from geoPlugin http://www.geoplugin.net/json.gp?ip=64.90.182.55 : geoPlugin({ geoplugin_request:64.90.182.55, geoplugin_status:200, geoplugin_city:New York,
Hi I have the following code: boolean result = someexpression(); if(!result) { System.out.println(False...); }
I have following select results: Select t1.ID, t1.Value1 from t1 where t1.ID=1 Result: ID
I have the following function: - (NSString *)urlEncodedValue { NSString *result = (NSString *)CFURLCreateStringByAddingPercentEscapes(
I have the following case where I get the result of UTF-8 encoded HTTP
I have the following code which definitely returns a proper data result if I
I have the following test - public void testStore() throws ItemNotStoredException { Boolean result
I have the following XML: <Result ID=1,New xmlns=http://schemas.microsoft.com/sharepoint/soap/> <ErrorCode>0x00000000</ErrorCode> <ID /> <z:row ows_ID=6 />
I have the following query with many LEFT JOIN clauses that has 7 result

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.