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
3,316 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,800 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,800 points
5,036 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,800 points
5,553 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
1,302 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
1,256 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,800 points
25,162 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,800 points
4,158 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,800 points
4,481 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,800 points
48,159 views
0 votes
1 answer

How to store values from foreach loop into an array?

sfsf gf fgfgf fhfh READ MORE

answered Nov 10, 2023 in PHP by anonymous

edited Mar 5, 2025 31,354 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,800 points
5,712 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