Find multiple results in array and echo them











up vote
-3
down vote

favorite












I've got a problem and I can't seem to find any answers on how to do this.



I've got an array example:



$data = array(
'8006309' => 'Pallet 1',
'8006309' => 'Pallet 2',
'8006309' => 'Pallet 2',
'8006309' => 'Pallet 3',
'8016493' => 'Pallet 4',
'8014376' => 'Pallet 5',
'8014375' => 'Pallet 5',
'8014375' => 'Pallet 5',
'8006401' => 'Pallet 6',
'8006310' => 'Pallet 6',
'8004263' => 'Pallet 6',
'8001038' => 'Pallet 6',
'8000697' => 'Pallet 6',
'004-9866' => 'Pallet 6'
);


As you can see there are rows with the same data, example: 8006309. I want to show the results when I search on 8006309, example:



Pallet 1
Pallet 2
Pallet 2
Pallet 3


Currently when I'm searching for the result, I only get the last value shown.



I'm not the best programmer out there, so this question might be cringey for some of you. Though I can't quite find how to do this?



Any help would be appreciated!










share|improve this question






















  • Where's the code that searches the array?
    – Magnus Eriksson
    Nov 22 at 9:45






  • 8




    You can't have the same array key twice (or more) in a single array. 8006309 will only be assigned to "Pallet 3" right now (it will constantly be overwritten).
    – Dirk Scholten
    Nov 22 at 9:45












  • Your example is incorrect, the keys should be unique.
    – kcats
    Nov 22 at 9:46










  • $data['8006309'] itself should be an array if you want/need multiple values
    – kerbholz
    Nov 22 at 9:46






  • 1




    Where is the input coming from?
    – Andreas
    Nov 22 at 9:47















up vote
-3
down vote

favorite












I've got a problem and I can't seem to find any answers on how to do this.



I've got an array example:



$data = array(
'8006309' => 'Pallet 1',
'8006309' => 'Pallet 2',
'8006309' => 'Pallet 2',
'8006309' => 'Pallet 3',
'8016493' => 'Pallet 4',
'8014376' => 'Pallet 5',
'8014375' => 'Pallet 5',
'8014375' => 'Pallet 5',
'8006401' => 'Pallet 6',
'8006310' => 'Pallet 6',
'8004263' => 'Pallet 6',
'8001038' => 'Pallet 6',
'8000697' => 'Pallet 6',
'004-9866' => 'Pallet 6'
);


As you can see there are rows with the same data, example: 8006309. I want to show the results when I search on 8006309, example:



Pallet 1
Pallet 2
Pallet 2
Pallet 3


Currently when I'm searching for the result, I only get the last value shown.



I'm not the best programmer out there, so this question might be cringey for some of you. Though I can't quite find how to do this?



Any help would be appreciated!










share|improve this question






















  • Where's the code that searches the array?
    – Magnus Eriksson
    Nov 22 at 9:45






  • 8




    You can't have the same array key twice (or more) in a single array. 8006309 will only be assigned to "Pallet 3" right now (it will constantly be overwritten).
    – Dirk Scholten
    Nov 22 at 9:45












  • Your example is incorrect, the keys should be unique.
    – kcats
    Nov 22 at 9:46










  • $data['8006309'] itself should be an array if you want/need multiple values
    – kerbholz
    Nov 22 at 9:46






  • 1




    Where is the input coming from?
    – Andreas
    Nov 22 at 9:47













up vote
-3
down vote

favorite









up vote
-3
down vote

favorite











I've got a problem and I can't seem to find any answers on how to do this.



I've got an array example:



$data = array(
'8006309' => 'Pallet 1',
'8006309' => 'Pallet 2',
'8006309' => 'Pallet 2',
'8006309' => 'Pallet 3',
'8016493' => 'Pallet 4',
'8014376' => 'Pallet 5',
'8014375' => 'Pallet 5',
'8014375' => 'Pallet 5',
'8006401' => 'Pallet 6',
'8006310' => 'Pallet 6',
'8004263' => 'Pallet 6',
'8001038' => 'Pallet 6',
'8000697' => 'Pallet 6',
'004-9866' => 'Pallet 6'
);


As you can see there are rows with the same data, example: 8006309. I want to show the results when I search on 8006309, example:



Pallet 1
Pallet 2
Pallet 2
Pallet 3


Currently when I'm searching for the result, I only get the last value shown.



I'm not the best programmer out there, so this question might be cringey for some of you. Though I can't quite find how to do this?



Any help would be appreciated!










share|improve this question













I've got a problem and I can't seem to find any answers on how to do this.



I've got an array example:



$data = array(
'8006309' => 'Pallet 1',
'8006309' => 'Pallet 2',
'8006309' => 'Pallet 2',
'8006309' => 'Pallet 3',
'8016493' => 'Pallet 4',
'8014376' => 'Pallet 5',
'8014375' => 'Pallet 5',
'8014375' => 'Pallet 5',
'8006401' => 'Pallet 6',
'8006310' => 'Pallet 6',
'8004263' => 'Pallet 6',
'8001038' => 'Pallet 6',
'8000697' => 'Pallet 6',
'004-9866' => 'Pallet 6'
);


As you can see there are rows with the same data, example: 8006309. I want to show the results when I search on 8006309, example:



Pallet 1
Pallet 2
Pallet 2
Pallet 3


Currently when I'm searching for the result, I only get the last value shown.



I'm not the best programmer out there, so this question might be cringey for some of you. Though I can't quite find how to do this?



Any help would be appreciated!







php arrays






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Nov 22 at 9:42









MrPerry95

196




196












  • Where's the code that searches the array?
    – Magnus Eriksson
    Nov 22 at 9:45






  • 8




    You can't have the same array key twice (or more) in a single array. 8006309 will only be assigned to "Pallet 3" right now (it will constantly be overwritten).
    – Dirk Scholten
    Nov 22 at 9:45












  • Your example is incorrect, the keys should be unique.
    – kcats
    Nov 22 at 9:46










  • $data['8006309'] itself should be an array if you want/need multiple values
    – kerbholz
    Nov 22 at 9:46






  • 1




    Where is the input coming from?
    – Andreas
    Nov 22 at 9:47


















  • Where's the code that searches the array?
    – Magnus Eriksson
    Nov 22 at 9:45






  • 8




    You can't have the same array key twice (or more) in a single array. 8006309 will only be assigned to "Pallet 3" right now (it will constantly be overwritten).
    – Dirk Scholten
    Nov 22 at 9:45












  • Your example is incorrect, the keys should be unique.
    – kcats
    Nov 22 at 9:46










  • $data['8006309'] itself should be an array if you want/need multiple values
    – kerbholz
    Nov 22 at 9:46






  • 1




    Where is the input coming from?
    – Andreas
    Nov 22 at 9:47
















Where's the code that searches the array?
– Magnus Eriksson
Nov 22 at 9:45




Where's the code that searches the array?
– Magnus Eriksson
Nov 22 at 9:45




8




8




You can't have the same array key twice (or more) in a single array. 8006309 will only be assigned to "Pallet 3" right now (it will constantly be overwritten).
– Dirk Scholten
Nov 22 at 9:45






You can't have the same array key twice (or more) in a single array. 8006309 will only be assigned to "Pallet 3" right now (it will constantly be overwritten).
– Dirk Scholten
Nov 22 at 9:45














Your example is incorrect, the keys should be unique.
– kcats
Nov 22 at 9:46




Your example is incorrect, the keys should be unique.
– kcats
Nov 22 at 9:46












$data['8006309'] itself should be an array if you want/need multiple values
– kerbholz
Nov 22 at 9:46




$data['8006309'] itself should be an array if you want/need multiple values
– kerbholz
Nov 22 at 9:46




1




1




Where is the input coming from?
– Andreas
Nov 22 at 9:47




Where is the input coming from?
– Andreas
Nov 22 at 9:47












2 Answers
2






active

oldest

votes

















up vote
0
down vote













You should have define your array element as another array, here is a test:



$data = array(
'8006309' => array('Pallet 1','Pallet 2', 'Pallet 3'),
'8016493' => 'Pallet 4',
'8014376' => 'Pallet 5',
'8014375' => 'Pallet 5',
'8014375' => 'Pallet 5',
'8006401' => 'Pallet 6',
'8006310' => 'Pallet 6',
'8004263' => 'Pallet 6',
'8001038' => 'Pallet 6',
'8000697' => 'Pallet 6',
'004-9866' => 'Pallet 6'
);





share|improve this answer




























    up vote
    0
    down vote













    You assign the same array key to multiple values. "8006309" will be overwritten til it reaches the last one.



    If you want to Store these Pallet Strings for every Key like 8006309 you should probably use a multidimensional array.



        $data = array(
    '8006309' => array('Pallet 1', 'Pallet 2', ...),
    '8004773' => array(...),
    ...);


    SO you have only one key assigned to multiple Pallets.
    You could also have Keys in the second array like:



        $data = array(
    '8006309' => array('firstOrder'=>'Pallet 1', 'secondOrder'=>'Pallet 2', ...),
    '8004773' => array(...),
    ...);





    share|improve this answer























      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',
      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%2f53427947%2ffind-multiple-results-in-array-and-echo-them%23new-answer', 'question_page');
      }
      );

      Post as a guest















      Required, but never shown

























      2 Answers
      2






      active

      oldest

      votes








      2 Answers
      2






      active

      oldest

      votes









      active

      oldest

      votes






      active

      oldest

      votes








      up vote
      0
      down vote













      You should have define your array element as another array, here is a test:



      $data = array(
      '8006309' => array('Pallet 1','Pallet 2', 'Pallet 3'),
      '8016493' => 'Pallet 4',
      '8014376' => 'Pallet 5',
      '8014375' => 'Pallet 5',
      '8014375' => 'Pallet 5',
      '8006401' => 'Pallet 6',
      '8006310' => 'Pallet 6',
      '8004263' => 'Pallet 6',
      '8001038' => 'Pallet 6',
      '8000697' => 'Pallet 6',
      '004-9866' => 'Pallet 6'
      );





      share|improve this answer

























        up vote
        0
        down vote













        You should have define your array element as another array, here is a test:



        $data = array(
        '8006309' => array('Pallet 1','Pallet 2', 'Pallet 3'),
        '8016493' => 'Pallet 4',
        '8014376' => 'Pallet 5',
        '8014375' => 'Pallet 5',
        '8014375' => 'Pallet 5',
        '8006401' => 'Pallet 6',
        '8006310' => 'Pallet 6',
        '8004263' => 'Pallet 6',
        '8001038' => 'Pallet 6',
        '8000697' => 'Pallet 6',
        '004-9866' => 'Pallet 6'
        );





        share|improve this answer























          up vote
          0
          down vote










          up vote
          0
          down vote









          You should have define your array element as another array, here is a test:



          $data = array(
          '8006309' => array('Pallet 1','Pallet 2', 'Pallet 3'),
          '8016493' => 'Pallet 4',
          '8014376' => 'Pallet 5',
          '8014375' => 'Pallet 5',
          '8014375' => 'Pallet 5',
          '8006401' => 'Pallet 6',
          '8006310' => 'Pallet 6',
          '8004263' => 'Pallet 6',
          '8001038' => 'Pallet 6',
          '8000697' => 'Pallet 6',
          '004-9866' => 'Pallet 6'
          );





          share|improve this answer












          You should have define your array element as another array, here is a test:



          $data = array(
          '8006309' => array('Pallet 1','Pallet 2', 'Pallet 3'),
          '8016493' => 'Pallet 4',
          '8014376' => 'Pallet 5',
          '8014375' => 'Pallet 5',
          '8014375' => 'Pallet 5',
          '8006401' => 'Pallet 6',
          '8006310' => 'Pallet 6',
          '8004263' => 'Pallet 6',
          '8001038' => 'Pallet 6',
          '8000697' => 'Pallet 6',
          '004-9866' => 'Pallet 6'
          );






          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Nov 22 at 10:03









          koviroli

          429311




          429311
























              up vote
              0
              down vote













              You assign the same array key to multiple values. "8006309" will be overwritten til it reaches the last one.



              If you want to Store these Pallet Strings for every Key like 8006309 you should probably use a multidimensional array.



                  $data = array(
              '8006309' => array('Pallet 1', 'Pallet 2', ...),
              '8004773' => array(...),
              ...);


              SO you have only one key assigned to multiple Pallets.
              You could also have Keys in the second array like:



                  $data = array(
              '8006309' => array('firstOrder'=>'Pallet 1', 'secondOrder'=>'Pallet 2', ...),
              '8004773' => array(...),
              ...);





              share|improve this answer



























                up vote
                0
                down vote













                You assign the same array key to multiple values. "8006309" will be overwritten til it reaches the last one.



                If you want to Store these Pallet Strings for every Key like 8006309 you should probably use a multidimensional array.



                    $data = array(
                '8006309' => array('Pallet 1', 'Pallet 2', ...),
                '8004773' => array(...),
                ...);


                SO you have only one key assigned to multiple Pallets.
                You could also have Keys in the second array like:



                    $data = array(
                '8006309' => array('firstOrder'=>'Pallet 1', 'secondOrder'=>'Pallet 2', ...),
                '8004773' => array(...),
                ...);





                share|improve this answer

























                  up vote
                  0
                  down vote










                  up vote
                  0
                  down vote









                  You assign the same array key to multiple values. "8006309" will be overwritten til it reaches the last one.



                  If you want to Store these Pallet Strings for every Key like 8006309 you should probably use a multidimensional array.



                      $data = array(
                  '8006309' => array('Pallet 1', 'Pallet 2', ...),
                  '8004773' => array(...),
                  ...);


                  SO you have only one key assigned to multiple Pallets.
                  You could also have Keys in the second array like:



                      $data = array(
                  '8006309' => array('firstOrder'=>'Pallet 1', 'secondOrder'=>'Pallet 2', ...),
                  '8004773' => array(...),
                  ...);





                  share|improve this answer














                  You assign the same array key to multiple values. "8006309" will be overwritten til it reaches the last one.



                  If you want to Store these Pallet Strings for every Key like 8006309 you should probably use a multidimensional array.



                      $data = array(
                  '8006309' => array('Pallet 1', 'Pallet 2', ...),
                  '8004773' => array(...),
                  ...);


                  SO you have only one key assigned to multiple Pallets.
                  You could also have Keys in the second array like:



                      $data = array(
                  '8006309' => array('firstOrder'=>'Pallet 1', 'secondOrder'=>'Pallet 2', ...),
                  '8004773' => array(...),
                  ...);






                  share|improve this answer














                  share|improve this answer



                  share|improve this answer








                  edited Nov 22 at 10:04

























                  answered Nov 22 at 9:58









                  xDrago

                  6417




                  6417






























                      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.





                      Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


                      Please pay close attention to the following guidance:


                      • 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%2f53427947%2ffind-multiple-results-in-array-and-echo-them%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

                      A CLEAN and SIMPLE way to add appendices to Table of Contents and bookmarks

                      Calculate evaluation metrics using cross_val_predict sklearn

                      Insert data from modal to MySQL (multiple modal on website)