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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T16:59:57+00:00 2026-05-27T16:59:57+00:00

I am using preg_match_all to pull phone numbers from a thread. This puts them

  • 0

I am using preg_match_all to pull phone numbers from a thread. This puts them into an array, im applying both rsort and array_unique to the matches variable, however they have no effect what so ever… The array_unique would eliminate matches that only come up from a quote or response duplicate, and the rsort should make the last index the first, the second to last index, second, etc…

preg_match_all('~0-9]{3}-[0-9]{3}-[0-9]{4}~', $data, $matches) 
$result = array_unique($matches);
rsort($result);
var_dump($result);

Output:

array
0 => 
array
  0 => string '111-111-1111' (length=12)
  1 => string '222-222-2222' (length=12)
  2 => string '333-333-3333' (length=12)
  3 => string '444-444-4444' (length=12)
  4 => string '555-555-5555' (length=12)
  5 => string '555-555-5555' (length=12)
  6 => string '555-555-5555' (length=12)

Needs to be:

array
0 => 
array
  0 => string '555-555-5555' (length=12)
  1 => string '444-444-4444' (length=12)
  2 => string '333-333-3333' (length=12)
  3 => string '222-222-2222' (length=12)
  4 => string '111-111-1111' (length=12)
  • 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-05-27T16:59:58+00:00Added an answer on May 27, 2026 at 4:59 pm

    I think you need the first element in the matches array.

    preg_match_all('~0-9]{3}-[0-9]{3}-[0-9]{4}~', $data, $matches) 
    $aList = $matches[0];
    $result = array_unique($aList);
    
    rsort($result);
    var_dump($result);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

preg_match_all('/(\d{4})/', $text, $matches); Using above function we can extract exact 4 digit numbers from
Using the following code I get img tags from some html and check them
I'm using this function from here , which is: // highlight search keywords function
I want to get the title of an article from this page using regex
I'm using preg_match_all for very long pattern. when run the code, i got this
i'm using preg_match_all('/<?(.*)?>/', $bigString, $matches, PREG_OFFSET_CAPTURE); to find the contents of everything between <?
Help with regular expressions needed. I'm trying using regular expressions and preg_match_all find blocks
first, this is using preg. String I'm trying to match: aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa b c d
I'm using preg_replace_callback to substitute particular tokens within the string. But apart from actual
I am having an issue removing %3Cbr+%2F%3E from my string using the preg_replace function.

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.