Array with similar value being removed The 2019 Stack Overflow Developer Survey Results Are InCreate ArrayList from arrayHow do I check if an array includes an object in JavaScript?How to append something to an array?PHP: Delete an element from an arrayHow do I determine whether an array contains a particular value in Java?Sort array of objects by string property valueLoop through an array in JavaScriptHow do I remove a particular element from an array in JavaScript?Copy array by valueHow to use foreach with array in JavaScript?

Did the UK government pay "millions and millions of dollars" to try to snag Julian Assange?

What information about me do stores get via my credit card?

Straighten subgroup lattice

Old scifi movie from the 50s or 60s with men in solid red uniforms who interrogate a spy from the past

I am an eight letter word. What am I?

Getting crown tickets for Statue of Liberty

If I can cast sorceries at instant speed, can I use sorcery-speed activated abilities at instant speed?

Did any laptop computers have a built-in 5 1/4 inch floppy drive?

Correct punctuation for showing a character's confusion

Why couldn't they take pictures of a closer black hole?

Relationship between Gromov-Witten and Taubes' Gromov invariant

How can I define good in a religion that claims no moral authority?

What is the most efficient way to store a numeric range?

Dropping list elements from nested list after evaluation

What to do when moving next to a bird sanctuary with a loosely-domesticated cat?

Why not take a picture of a closer black hole?

Why isn't the circumferential light around the M87 black hole's event horizon symmetric?

Why are there uneven bright areas in this photo of black hole?

Is it safe to harvest rainwater that fell on solar panels?

Accepted by European university, rejected by all American ones I applied to? Possible reasons?

What do these terms in Caesar's Gallic wars mean?

How come people say “Would of”?

Is an up-to-date browser secure on an out-of-date OS?

Is it ok to offer lower paid work as a trial period before negotiating for a full-time job?



Array with similar value being removed



The 2019 Stack Overflow Developer Survey Results Are InCreate ArrayList from arrayHow do I check if an array includes an object in JavaScript?How to append something to an array?PHP: Delete an element from an arrayHow do I determine whether an array contains a particular value in Java?Sort array of objects by string property valueLoop through an array in JavaScriptHow do I remove a particular element from an array in JavaScript?Copy array by valueHow to use foreach with array in JavaScript?



.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty height:90px;width:728px;box-sizing:border-box;








0















Basically, I've list of associative array and I'm trying to output both key and value for all. Here's the code I have.



$sites = array("www.google.com" => "Google", "www.apple.com" => "Apple", 
"www.apple.com" => "Apple");
foreach ($sites as $url => $name )
echo $name . " " . $url . "<br/>";



As you can see 'apple' is being repeated and hence it's not being displayed in foreach loop. Here's the output of code above.



Google www.google.com
Apple www.apple.com


How to display all array values?



Thanks.










share|improve this question

















  • 4





    You can't have 2 values in an associate array with the same index.

    – user1334621
    Mar 22 at 4:34












  • Make Array of Array

    – Niklesh Raut
    Mar 22 at 4:37











  • You can use simple array_unique() function to remove duplicate values.

    – Mayank Dudakiya
    Mar 22 at 4:45











  • @catcon Thanks. This fixed it.

    – shutupchigo
    Mar 22 at 4:45











  • I have added my answer with the use of array_unique()

    – Mayank Dudakiya
    Mar 22 at 4:48

















0















Basically, I've list of associative array and I'm trying to output both key and value for all. Here's the code I have.



$sites = array("www.google.com" => "Google", "www.apple.com" => "Apple", 
"www.apple.com" => "Apple");
foreach ($sites as $url => $name )
echo $name . " " . $url . "<br/>";



As you can see 'apple' is being repeated and hence it's not being displayed in foreach loop. Here's the output of code above.



Google www.google.com
Apple www.apple.com


How to display all array values?



Thanks.










share|improve this question

















  • 4





    You can't have 2 values in an associate array with the same index.

    – user1334621
    Mar 22 at 4:34












  • Make Array of Array

    – Niklesh Raut
    Mar 22 at 4:37











  • You can use simple array_unique() function to remove duplicate values.

    – Mayank Dudakiya
    Mar 22 at 4:45











  • @catcon Thanks. This fixed it.

    – shutupchigo
    Mar 22 at 4:45











  • I have added my answer with the use of array_unique()

    – Mayank Dudakiya
    Mar 22 at 4:48













0












0








0








Basically, I've list of associative array and I'm trying to output both key and value for all. Here's the code I have.



$sites = array("www.google.com" => "Google", "www.apple.com" => "Apple", 
"www.apple.com" => "Apple");
foreach ($sites as $url => $name )
echo $name . " " . $url . "<br/>";



As you can see 'apple' is being repeated and hence it's not being displayed in foreach loop. Here's the output of code above.



Google www.google.com
Apple www.apple.com


How to display all array values?



Thanks.










share|improve this question














Basically, I've list of associative array and I'm trying to output both key and value for all. Here's the code I have.



$sites = array("www.google.com" => "Google", "www.apple.com" => "Apple", 
"www.apple.com" => "Apple");
foreach ($sites as $url => $name )
echo $name . " " . $url . "<br/>";



As you can see 'apple' is being repeated and hence it's not being displayed in foreach loop. Here's the output of code above.



Google www.google.com
Apple www.apple.com


How to display all array values?



Thanks.







php arrays associative-array






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Mar 22 at 4:31









shutupchigoshutupchigo

18410




18410







  • 4





    You can't have 2 values in an associate array with the same index.

    – user1334621
    Mar 22 at 4:34












  • Make Array of Array

    – Niklesh Raut
    Mar 22 at 4:37











  • You can use simple array_unique() function to remove duplicate values.

    – Mayank Dudakiya
    Mar 22 at 4:45











  • @catcon Thanks. This fixed it.

    – shutupchigo
    Mar 22 at 4:45











  • I have added my answer with the use of array_unique()

    – Mayank Dudakiya
    Mar 22 at 4:48












  • 4





    You can't have 2 values in an associate array with the same index.

    – user1334621
    Mar 22 at 4:34












  • Make Array of Array

    – Niklesh Raut
    Mar 22 at 4:37











  • You can use simple array_unique() function to remove duplicate values.

    – Mayank Dudakiya
    Mar 22 at 4:45











  • @catcon Thanks. This fixed it.

    – shutupchigo
    Mar 22 at 4:45











  • I have added my answer with the use of array_unique()

    – Mayank Dudakiya
    Mar 22 at 4:48







4




4





You can't have 2 values in an associate array with the same index.

– user1334621
Mar 22 at 4:34






You can't have 2 values in an associate array with the same index.

– user1334621
Mar 22 at 4:34














Make Array of Array

– Niklesh Raut
Mar 22 at 4:37





Make Array of Array

– Niklesh Raut
Mar 22 at 4:37













You can use simple array_unique() function to remove duplicate values.

– Mayank Dudakiya
Mar 22 at 4:45





You can use simple array_unique() function to remove duplicate values.

– Mayank Dudakiya
Mar 22 at 4:45













@catcon Thanks. This fixed it.

– shutupchigo
Mar 22 at 4:45





@catcon Thanks. This fixed it.

– shutupchigo
Mar 22 at 4:45













I have added my answer with the use of array_unique()

– Mayank Dudakiya
Mar 22 at 4:48





I have added my answer with the use of array_unique()

– Mayank Dudakiya
Mar 22 at 4:48












3 Answers
3






active

oldest

votes


















1














Construct multidimensional array as follows. Because your array has duplicate indexes.
$sites = [
["www.google.com" => "Google"],
["www.apple.com" => "Apple"],
["www.apple.com" => "Apple"]
];

foreach ($sites as $url_arr )
foreach ($url_arr as $url => $name )
echo $name . " " . $url . "<br/>";







share|improve this answer






























    0














    Index cannot be the same ,hope this helps



    $sites = array(array("www.google.com" => "Google"),array( "www.apple.com" => "Apple"), 
    array("www.apple.com" => "Apple"));
    foreach ($sites as $key => $value )

    foreach($sites[$key] as $key1 =>$value1)


    echo $sites[$key][$key1] . " " . $key1 . "<br/>";








    share|improve this answer






























      0














      No need to use any for loop.



      You just need to use **array_unique()** function to remove duplicate values.



      <?php

      $sites = array("www.google.com" => "Google", "www.apple.com" => "Apple",
      "www.apple.com" => "Apple");

      print_r(array_unique($sites));
      ?>



      Output will be like following




      Array ( [www.google.com] => Google [www.apple.com] => Apple ) 





      share|improve this answer























      • He wanted to display all values.

        – cha
        Mar 22 at 4:51











      Your Answer






      StackExchange.ifUsing("editor", function ()
      StackExchange.using("externalEditor", function ()
      StackExchange.using("snippets", function ()
      StackExchange.snippets.init();
      );
      );
      , "code-snippets");

      StackExchange.ready(function()
      var channelOptions =
      tags: "".split(" "),
      id: "1"
      ;
      initTagRenderer("".split(" "), "".split(" "), channelOptions);

      StackExchange.using("externalEditor", function()
      // Have to fire editor after snippets, if snippets enabled
      if (StackExchange.settings.snippets.snippetsEnabled)
      StackExchange.using("snippets", function()
      createEditor();
      );

      else
      createEditor();

      );

      function createEditor()
      StackExchange.prepareEditor(
      heartbeatType: 'answer',
      autoActivateHeartbeat: false,
      convertImagesToLinks: true,
      noModals: true,
      showLowRepImageUploadWarning: true,
      reputationToPostImages: 10,
      bindNavPrevention: true,
      postfix: "",
      imageUploader:
      brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
      contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
      allowUrls: true
      ,
      onDemand: true,
      discardSelector: ".discard-answer"
      ,immediatelyShowMarkdownHelp:true
      );



      );













      draft saved

      draft discarded


















      StackExchange.ready(
      function ()
      StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55292961%2farray-with-similar-value-being-removed%23new-answer', 'question_page');

      );

      Post as a guest















      Required, but never shown

























      3 Answers
      3






      active

      oldest

      votes








      3 Answers
      3






      active

      oldest

      votes









      active

      oldest

      votes






      active

      oldest

      votes









      1














      Construct multidimensional array as follows. Because your array has duplicate indexes.
      $sites = [
      ["www.google.com" => "Google"],
      ["www.apple.com" => "Apple"],
      ["www.apple.com" => "Apple"]
      ];

      foreach ($sites as $url_arr )
      foreach ($url_arr as $url => $name )
      echo $name . " " . $url . "<br/>";







      share|improve this answer



























        1














        Construct multidimensional array as follows. Because your array has duplicate indexes.
        $sites = [
        ["www.google.com" => "Google"],
        ["www.apple.com" => "Apple"],
        ["www.apple.com" => "Apple"]
        ];

        foreach ($sites as $url_arr )
        foreach ($url_arr as $url => $name )
        echo $name . " " . $url . "<br/>";







        share|improve this answer

























          1












          1








          1







          Construct multidimensional array as follows. Because your array has duplicate indexes.
          $sites = [
          ["www.google.com" => "Google"],
          ["www.apple.com" => "Apple"],
          ["www.apple.com" => "Apple"]
          ];

          foreach ($sites as $url_arr )
          foreach ($url_arr as $url => $name )
          echo $name . " " . $url . "<br/>";







          share|improve this answer













          Construct multidimensional array as follows. Because your array has duplicate indexes.
          $sites = [
          ["www.google.com" => "Google"],
          ["www.apple.com" => "Apple"],
          ["www.apple.com" => "Apple"]
          ];

          foreach ($sites as $url_arr )
          foreach ($url_arr as $url => $name )
          echo $name . " " . $url . "<br/>";








          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Mar 22 at 4:44









          chacha

          5602921




          5602921























              0














              Index cannot be the same ,hope this helps



              $sites = array(array("www.google.com" => "Google"),array( "www.apple.com" => "Apple"), 
              array("www.apple.com" => "Apple"));
              foreach ($sites as $key => $value )

              foreach($sites[$key] as $key1 =>$value1)


              echo $sites[$key][$key1] . " " . $key1 . "<br/>";








              share|improve this answer



























                0














                Index cannot be the same ,hope this helps



                $sites = array(array("www.google.com" => "Google"),array( "www.apple.com" => "Apple"), 
                array("www.apple.com" => "Apple"));
                foreach ($sites as $key => $value )

                foreach($sites[$key] as $key1 =>$value1)


                echo $sites[$key][$key1] . " " . $key1 . "<br/>";








                share|improve this answer

























                  0












                  0








                  0







                  Index cannot be the same ,hope this helps



                  $sites = array(array("www.google.com" => "Google"),array( "www.apple.com" => "Apple"), 
                  array("www.apple.com" => "Apple"));
                  foreach ($sites as $key => $value )

                  foreach($sites[$key] as $key1 =>$value1)


                  echo $sites[$key][$key1] . " " . $key1 . "<br/>";








                  share|improve this answer













                  Index cannot be the same ,hope this helps



                  $sites = array(array("www.google.com" => "Google"),array( "www.apple.com" => "Apple"), 
                  array("www.apple.com" => "Apple"));
                  foreach ($sites as $key => $value )

                  foreach($sites[$key] as $key1 =>$value1)


                  echo $sites[$key][$key1] . " " . $key1 . "<br/>";









                  share|improve this answer












                  share|improve this answer



                  share|improve this answer










                  answered Mar 22 at 4:43









                  DeepakDeepak

                  55110




                  55110





















                      0














                      No need to use any for loop.



                      You just need to use **array_unique()** function to remove duplicate values.



                      <?php

                      $sites = array("www.google.com" => "Google", "www.apple.com" => "Apple",
                      "www.apple.com" => "Apple");

                      print_r(array_unique($sites));
                      ?>



                      Output will be like following




                      Array ( [www.google.com] => Google [www.apple.com] => Apple ) 





                      share|improve this answer























                      • He wanted to display all values.

                        – cha
                        Mar 22 at 4:51















                      0














                      No need to use any for loop.



                      You just need to use **array_unique()** function to remove duplicate values.



                      <?php

                      $sites = array("www.google.com" => "Google", "www.apple.com" => "Apple",
                      "www.apple.com" => "Apple");

                      print_r(array_unique($sites));
                      ?>



                      Output will be like following




                      Array ( [www.google.com] => Google [www.apple.com] => Apple ) 





                      share|improve this answer























                      • He wanted to display all values.

                        – cha
                        Mar 22 at 4:51













                      0












                      0








                      0







                      No need to use any for loop.



                      You just need to use **array_unique()** function to remove duplicate values.



                      <?php

                      $sites = array("www.google.com" => "Google", "www.apple.com" => "Apple",
                      "www.apple.com" => "Apple");

                      print_r(array_unique($sites));
                      ?>



                      Output will be like following




                      Array ( [www.google.com] => Google [www.apple.com] => Apple ) 





                      share|improve this answer













                      No need to use any for loop.



                      You just need to use **array_unique()** function to remove duplicate values.



                      <?php

                      $sites = array("www.google.com" => "Google", "www.apple.com" => "Apple",
                      "www.apple.com" => "Apple");

                      print_r(array_unique($sites));
                      ?>



                      Output will be like following




                      Array ( [www.google.com] => Google [www.apple.com] => Apple ) 






                      share|improve this answer












                      share|improve this answer



                      share|improve this answer










                      answered Mar 22 at 4:48









                      Mayank DudakiyaMayank Dudakiya

                      668315




                      668315












                      • He wanted to display all values.

                        – cha
                        Mar 22 at 4:51

















                      • He wanted to display all values.

                        – cha
                        Mar 22 at 4:51
















                      He wanted to display all values.

                      – cha
                      Mar 22 at 4:51





                      He wanted to display all values.

                      – cha
                      Mar 22 at 4:51

















                      draft saved

                      draft discarded
















































                      Thanks for contributing an answer to Stack Overflow!


                      • Please be sure to answer the question. Provide details and share your research!

                      But avoid


                      • Asking for help, clarification, or responding to other answers.

                      • Making statements based on opinion; back them up with references or personal experience.

                      To learn more, see our tips on writing great answers.




                      draft saved


                      draft discarded














                      StackExchange.ready(
                      function ()
                      StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55292961%2farray-with-similar-value-being-removed%23new-answer', 'question_page');

                      );

                      Post as a guest















                      Required, but never shown





















































                      Required, but never shown














                      Required, but never shown












                      Required, but never shown







                      Required, but never shown

































                      Required, but never shown














                      Required, but never shown












                      Required, but never shown







                      Required, but never shown







                      Popular posts from this blog

                      SQL error code 1064 with creating Laravel foreign keysForeign key constraints: When to use ON UPDATE and ON DELETEDropping column with foreign key Laravel error: General error: 1025 Error on renameLaravel SQL Can't create tableLaravel Migration foreign key errorLaravel php artisan migrate:refresh giving a syntax errorSQLSTATE[42S01]: Base table or view already exists or Base table or view already exists: 1050 Tableerror in migrating laravel file to xampp serverSyntax error or access violation: 1064:syntax to use near 'unsigned not null, modelName varchar(191) not null, title varchar(191) not nLaravel cannot create new table field in mysqlLaravel 5.7:Last migration creates table but is not registered in the migration table

                      용인 삼성생명 블루밍스 목차 통계 역대 감독 선수단 응원단 경기장 같이 보기 외부 링크 둘러보기 메뉴samsungblueminx.comeh선수 명단용인 삼성생명 블루밍스용인 삼성생명 블루밍스ehsamsungblueminx.comeheheheh

                      155 수학 과학 기타 둘러보기 메뉴eh추가해eh문서를 완성해