Answer the question
In order to leave comments, you need to log in
How to compare two arrays by the first character of the values and if they match, remove those values from the first array?
Hello, there are two such arrays:
Array
(
[0] => 0-1439802876-55d1a5fc8879e.jpg
[1] => 1-1439802876-55d1a5fc8ed30.jpg
[2] => 2-1439802876-55d1a5fc95a91.jpg
)
Array
(
[0] => 0-1440719577-55dfa2d9195ec.jpg
[1] => 2-1440719577-55dfa2d93572b.jpg
[2] => 3-1440719577-55dfa2d951c51.jpg
)
Answer the question
In order to leave comments, you need to log in
<?php
$a = array(
"0-1439802876-55d1a5fc8879e.jpg",
"1-1439802876-55d1a5fc8ed30.jpg",
"2-1439802876-55d1a5fc95a91.jpg",
);
$b = array(
"0-1440719577-55dfa2d9195ec.jpg",
"2-1440719577-55dfa2d93572b.jpg",
"3-1440719577-55dfa2d951c51.jpg",
);
$a = array_combine(array_map(function ($v) {
return substr($v, 0, strpos($v, '-'));
}, $a), $a);
$b = array_combine(array_map(function ($v) {
return substr($v, 0, strpos($v, '-'));
}, $b), $b);
print_r($a+$b);
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question