Jump to content

loop multidimensional array

Go to solution Solved by mac_gyver,

Recommended Posts

my preg_match_all works perfectly. I just can't figure out how to loop through the "$matches" array it creates.
preg_match_all( $pattern , $string , $matches);

The code print_r($matches) yields the following super simple array.

    [0] => Array
            [0] => 123456wordsandwordsandmorestuff$40.97
            [1] => 987654wordsandmorewords$26.79

    [1] => Array
            [0] => 123456  <----------this goes with the [0] below
            [1] => 987654  <----------this goes with the [1] below

    [2] => Array
            [0] => $40.97  <-----------this goes with the [0] above
            [1] => $26.79  <-----------this goes with the [1] above


The problem is I can't figure out how to do the foreach() loop to get this:

SKU number 123456 costs $40.97
SKU number 978654 costs $26.79

I know the answer will be embarrasingly simple..... but I've tried at least 200 different foreach variations and I am close to giving up.



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.

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.