mysql — поиск в 2d массиве и сравнение с базой данных в Stack Overflow

У меня есть 2D-массив, который выглядит так:

    Array
(
[0] => Array
(
[0] => 0024E8D4915C
[1] => 0026B9AC17A0
[2] => 080027042B7C
[3] => 1866DA0EBD4C
[4] => " "\\&
O��"[6] => 64006A5F5DE0
[7] => B05ADACE88BC
[8] => B439D6388380
[9] => D067E51A3B4F
[10] => D4BED9C2B47F
[11] => D4C9EFB500A3
[12] => "�M��>�"[13] => F48E382F5B06
)

[1] => Array
(
[0] =>  25
[1] =>  25
[2] =>  25
[3] =>  25
[4] =>  25
[5] =>  25
[6] =>  25
[7] =>  25
[8] =>  0
[9] =>  25
[10] =>  25
[11] =>  25
[12] =>  25
[13] =>  25
)

)

0

Решение

//suppose your array's name is $array

for ($i=0; $i < count($array[0]); $i++) {
$res[] = array(
'mac' => $array[0][$i],
'port' => $array[1][$i]
);
}

print_r($res);
0

Другие решения

Почему бы вам не создать массив, который выглядит так?

Array(
[0] => Array(
['mac'] => '0026B9AC17A0',
['port'] => 25
),
[1] => Array(
['mac'] => '080027042B7C',
['port'] => 25
),
[2] => Array(
['mac'] => 'B439D6388380',
['port'] => 0
)
...
)
0

Вы можете попробовать следующий код: eval.in. В конце концов вы можете удалить пустые или странные символы.

<?php

$dbArray = [
"0026B9AC17A0",
"008064A890B2",
"1866DA3440E9",
"3464A9D5B334",
"5C260A4F8B7F",
"0050568A6F7B"];

$resultArray = [
[
"0024E8D4915C",
"0026B9AC17A0",
"080027042B7C",
"1866DA0EBD4C",
"",
"",
"64006A5F5DE0",
"B05ADACE88BC",
"B439D6388380",
"D067E51A3B4F",
"D4BED9C2B47F",
"D4C9EFB500A3",
"M000000",
"F48E382F5B06"],
[ "25", "25", "25", "25", "25", "25", "25", "25", "0", "25", "25", "25", "25", "25"]
];
echo "mac address: \t port number:\n";
foreach($resultArray[0] as $key=> $value){
if(!in_array($value, $dbArray)){
echo $value ." \t ". $resultArray[1][$key] ."\n";
}
}
0
По вопросам рекламы [email protected]