Find multiple results in array and echo them
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
add a comment |
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
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
add a comment |
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
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
php arrays
asked Nov 22 at 9:42
MrPerry95
197
197
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
add a comment |
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
add a comment |
2 Answers
2
active
oldest
votes
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'
);
add a comment |
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(...),
...);
add a comment |
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
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
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'
);
add a comment |
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'
);
add a comment |
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'
);
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'
);
answered Nov 22 at 10:03
koviroli
454311
454311
add a comment |
add a comment |
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(...),
...);
add a comment |
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(...),
...);
add a comment |
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(...),
...);
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(...),
...);
edited Nov 22 at 10:04
answered Nov 22 at 9:58
xDrago
6417
6417
add a comment |
add a comment |
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.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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
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