PHP Array Exercises : Merge two commas separated lists with unique value only
PHP Array: Exercise-43 with Solution
Write a PHP script to merge two commas separated lists with unique value only.
<?php $list1 = "4, 5, 6, 7"; $list2 = "4, 5, 7, 8"; // combine both lists with unique values only $result = implode("," , array_unique(array_merge(explode(",",$list1),explode(",", $list2)))); echo $result."\n"; ?>
4, 5, 6, 7, 8
PHP Code Editor:
Contribute your code and comments through Disqus.
What is the difficulty level of this exercise?
PHP: Tips of the Day
PHP: Extract numbers from a string
$str = 'In My Cart : 11 12 items'; preg_match_all('!\d+!', $str, $matches); print_r($matches);
- New Content published on w3resource:
- Scala Programming Exercises, Practice, Solution
- Python Itertools exercises
- Python Numpy exercises
- Python GeoPy Package exercises
- Python Pandas exercises
- Python nltk exercises
- Python BeautifulSoup exercises
- Form Template
- Composer - PHP Package Manager
- PHPUnit - PHP Testing
- Laravel - PHP Framework