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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T12:59:31+00:00 2026-06-03T12:59:31+00:00

I have this two arrays. one is generated using a standard SELECT query, the

  • 0

I have this two arrays.

one is generated using a standard SELECT query, the other one is generated using this statement:

$file = file(DOC_ROOT."robots.txt");
foreach($file as $text) {
$test[] = $text;
}

the first array output like this:

Array
(
    [0] => Disallow: /admin/
    [1] => Disallow: /m/
    [2] => Disallow: /private/
)

the other like this:

Array
(
[4] => Disallow: /admin/

[5] => Disallow: /m/

[6] => Disallow: /private/

[7] => Disallow: /success.php
)

the problem now is that after merging the two arrays, array_unique doesn’t work, im guessing maybe its caused by the spaces generated by the second array, i’ve tried removing them but with no luck. now my question is, is it really the spaces that cause this or is there something wrong with my flow? for your convenience here is the array code, not that it would matter that much. How will i be able to solve this problem? Thank you.

$result = array_merge($lines,$test);
    $result = array_unique($result);
    echo '<pre>';
    echo print_r($result);
    echo '</pre>';

the result:

Array
(
[0] => Disallow: /admin/
[1] => Disallow: /m/
[2] => Disallow: /private/

[32] => 

[33] => Disallow: /admin/

[34] => Disallow: /m/

[35] => Disallow: /private/

[36] => Disallow: /success.php
)
  • 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-03T12:59:33+00:00Added an answer on June 3, 2026 at 12:59 pm

    array_unique() works on array’s values. In your example there aren’t any value in common so it will not delete any values.

    And yes spaces make array_unique see 2 different values, so basicalyl these 2 values are not the same:

    [0] => 'hello1   hello2'
    [1] => 'hello1 hello2'
    

    and array_unique leaves both values

    You have that space between keys within pre because file() keeps \n and \r. So do a:

    file(,FILE_IGNORE_NEW_LINES);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have two arrays the first one has this structure Parameter Keys array array
I have converted an array to object data like this: <?php $myobject->data = (object)Array('zero','one','two');
i have two arrays like this first array Array ( [0228] => Array (
I have two arrays that I create like this: public int GameBoard[][] = new
I have two arrays with time values in them in this format. 00:00:00 which
Is there any way to have this: [one[two]][three] And extract this with a regex?
So I have a couple of arrays $array_1 = Array('one','two','three'); $array_2 = Array('red','blue','green'); Is
I have this array that searches for matches between two arrays. The problem is
I have an two arrays, one is cityUSA[i] and one is decimalUSA[i]. Each has
I have a two-dimensional array. When I print/dump this I get the following My

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.