How to remove duplicate values from an array in PHP

0 votes
How can I remove duplicate values from an array in PHP?
Sep 15, 2020 in PHP by kartik
• 37,520 points
2,737 views

1 answer to this question.

0 votes

Hello @kartik,

Use array_unique():

Example:

$array = array(1, 2, 2, 3);
$array = array_unique($array); // Array is now (1, 2, 3)

Hope it helps!!

Thank You!!

answered Sep 15, 2020 by Niroj
• 82,840 points

Related Questions In PHP

0 votes
1 answer

How to allow duplicate keys in php array?

Hello @kartik, You could have a single key ...READ MORE

answered Nov 19, 2020 in PHP by Niroj
• 82,840 points
3,938 views
0 votes
1 answer

How to pass an array via $_GET in php?

Hii, You can pass an associative array to http_build_query() and ...READ MORE

answered Nov 22, 2020 in PHP by Niroj
• 82,840 points
4,457 views
0 votes
0 answers

How to convert an array to a string in PHP?

What can I do to get the ...READ MORE

May 30, 2022 in PHP by Kichu
• 19,040 points
622 views
0 votes
0 answers

How to convert a string to an array in php

I want to convert a string into ...READ MORE

Jun 1, 2022 in PHP by Kichu
• 19,040 points
536 views
+1 vote
1 answer

How to make anchor tag with routing using Laravel?

Hey @kartik, First you have to go to ...READ MORE

answered Mar 18, 2020 in Laravel by Niroj
• 82,840 points
23,012 views
0 votes
1 answer

What is redirection in Laravel?

Named route is used to give specific ...READ MORE

answered Mar 18, 2020 in Laravel by Niroj
• 82,840 points
2,995 views
0 votes
1 answer

How to install Laravel via composer?

Hello, This is simple you just need to ...READ MORE

answered Mar 23, 2020 in Laravel by Niroj
• 82,840 points
2,918 views
+1 vote
1 answer

What are named routes in Laravel and How can specify route names for controller actions?

Hey @kartik, Named routing is another amazing feature of ...READ MORE

answered Mar 23, 2020 in Laravel by Niroj
• 82,840 points
44,692 views
0 votes
1 answer

How to store values from foreach loop into an array?

Hello @kartik, Declare the $items array outside the loop and ...READ MORE

answered Sep 1, 2020 in PHP by Niroj
• 82,840 points
30,047 views
0 votes
1 answer

How to remove a variable from a PHP session array?

Hello @kartik, Try: if (isset($_POST['remove'])) { ...READ MORE

answered Nov 8, 2020 in PHP by Niroj
• 82,840 points
4,839 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP