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;
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
add a comment |
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
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
add a comment |
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
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
php arrays associative-array
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
add a comment |
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
add a comment |
3 Answers
3
active
oldest
votes
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/>";
add a comment |
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/>";
add a comment |
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 )
He wanted to display all values.
– cha
Mar 22 at 4:51
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%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
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/>";
add a comment |
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/>";
add a comment |
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/>";
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/>";
answered Mar 22 at 4:44
chacha
5602921
5602921
add a comment |
add a comment |
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/>";
add a comment |
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/>";
add a comment |
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/>";
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/>";
answered Mar 22 at 4:43
DeepakDeepak
55110
55110
add a comment |
add a comment |
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 )
He wanted to display all values.
– cha
Mar 22 at 4:51
add a comment |
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 )
He wanted to display all values.
– cha
Mar 22 at 4:51
add a comment |
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 )
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 )
answered Mar 22 at 4:48
Mayank DudakiyaMayank Dudakiya
668315
668315
He wanted to display all values.
– cha
Mar 22 at 4:51
add a comment |
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
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.
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%2f55292961%2farray-with-similar-value-being-removed%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
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