如何只获取数组中的唯一值以及如何删除空白数组。
我如何检查第一个值条件,如mydata1是唯一的,如果发现mydata1多一次然后删除完整数组检查我的输出..
Array
(
[0] => Array
(
[0] => Mydata1
[1] => first
[2] => first
)
[1] => Array
(
[0] =>
[1] =>
[2] =>
)
[2] => Array
(
[0] => Mydata3
[1] => second
[2] => first
)
[3] => Array
(
[0] => Mydata1
[1] => first
[1] => dddemo
)
[4] => Array
(
[0] => Mydata1
[1] => fourth
[2] => first
)
[5] => Array
(
[0] => Mydata3
[1] => fifth
[2] => first
)
[6] => Array
(
[0] => Mydata2
[1] => sixth
[2] => first
)
)
/////////////////////////////////////////////// //////////////////
输出:
Array
(
[0] => Array
(
[0] => Mydata1
[1] => first
[2] => first
)
[1] => Array
(
[0] => Mydata3
[1] => second
[2] => first
)
[2] => Array
(
[0] => Mydata2
[1] => sixth
[2] => first
)
)
答案 0 :(得分:0)
好的,这是我的解决方案:
$array = [
0 => [
'Mydata1',
'first',
'first',
],
1 => [
null,
null,
null,
],
2 => [
'Mydata3',
'second',
'first',
],
3 => [
'Mydata1',
'first',
'dddemo',
],
4 => [
'Mydata1',
'fourth',
'first',
],
0 => [
'Mydata3',
'fifth',
'first',
],
0 => [
'Mydata2',
'sixth',
'first',
],
];
$newarray = [];
foreach ($array as $key => $data)
{
$flag = true;
foreach ($newarray as $new)
{
if ($new[0] == $data[0])
{
$flag = false;
}
}
if ($flag && isset($data[0]))
{
$newarray[count($newarray)] = $data;
}
}
var_dump($newarray);
// Outputs
array(3) {
[0]=> array(3) {
[0]=>
string(7) "Mydata2"
[1]=>
string(5) "sixth"
[2]=>
string(5) "first"
}
[1]=> array(3) {
[0]=>
string(7) "Mydata3"
[1]=>
string(6) "second"
[2]=>
string(5) "first"
}
[2]=> array(3) {
[0]=>
string(7) "Mydata1"
[1]=>
string(5) "first"
[2]=>
string(6) "dddemo"
}
}