У меня проблема с многомерным массивом. Числа взяты из текстового файла, эти числа должны быть проверены в двумерном массиве. Код таков:
$settori = [0 =>[7,28,12,35,3,26,0,32,15,19,4,21,2], 32 =>[28,12,35,3,26,0,32,15,19,4,21,2,25], 15 =>[12,35,3,26,0,32,15,19,4,21,2,25,17], 19 =>[35,3,26,0,32,15,19,4,21,2,25,17,34], 4 =>[3,26,0,32,15,19,4,21,2,25,17,34,6], 21 =>[26,0,32,15,19,4,21,2,25,17,34,6,27], 2 =>[0,32,15,19,4,21,2,25,17,34,6,27,13], 25 =>[32,15,19,4,21,2,25,17,34,6,27,13,36], 17 =>[15,19,4,21,2,25,17,34,6,27,13,36,11], 34 => [19,4,21,2,25,17,34,6,27,13,36,11,30], 6 => [4,21,2,25,17,34,6,27,13,36,11,30,8], 27 => [21,2,25,17,34,6,27,13,36,11,30,8,23], 13 => [2,25,17,34,6,27,13,36,11,30,8,23,10], 36 => [25,17,34,6,27,13,36,11,30,8,23,10,5], 11 => [17,34,6,27,13,36,11,30,8,23,10,5,24], 30 => [34,6,27,13,36,11,30,8,23,10,5,24,16], 8 => [6,27,13,36,11,30,8,23,10,5,24,16,33], 23 => [27,13,36,11,30,8,23,10,5,24,16,33,1], 10 => [13,36,11,30,8,23,10,5,24,16,33,1,20], 5 => [36,11,30,8,23,10,5,24,16,33,1,20,14], 24 => [11,30,8,23,10,5,24,16,33,1,20,14,31], 16 => [30,8,23,10,5,24,16,33,1,20,14,31,9], 33 => [8,23,10,5,24,16,33,1,20,14,31,9,22], 1 => [23,10,5,24,16,33,1,20,14,31,9,22,18], 20 => [10,5,24,16,33,1,20,14,31,9,22,18,29], 14 => [5,24,16,33,1,20,14,31,9,22,18,29,7], 31 => [24,16,33,1,20,14,31,9,22,18,29,7,28], 9 => [16,33,1,20,14,31,9,22,18,29,7,28,12], 22 => [33,1,20,14,31,9,22,18,29,7,28,12,35], 18 => [1,20,14,31,9,22,18,29,7,28,12,35,3], 29 => [20,14,31,9,22,18,29,7,28,12,35,3,26], 7 => [14,31,9,22,18,29,7,28,12,35,3,26,0], 28 => [31,9,22,18,29,7,28,12,35,3,26,0,32], 12 => [9,22,18,29,7,28,12,35,3,26,0,32,15], 35 => [22,18,29,7,28,12,35,3,26,0,32,15,19], 3 => [18,29,7,28,12,35,3,26,0,32,15,19,4], 26 => [29,7,28,12,35,3,26,0,32,15,19,4,21]];
$settoriInGioco = [];
$settoreInGioco = 100;
$gioco = false;
//$number is the number taken from the file
foreach($arrayTxtPermanenza as $key => $number) ...............
if (count($settoriInGioco) == 0) {
$settoriInGioco[] = $number;
} else {
foreach ($settoriInGioco as $val) {
echo $val."<br>"; // echo is printed correctly
if (in_array($number, $settori[$val])) { <-- the problem is here $settori[$val] is nil!
$settoreInGioco = $val;
$eNelCiclo = 1;
break;
}
}
if ($eNelCiclo == 0) {
$settoriInGioco[] = $number;
}
}
........
Проблема в том, что даже если я правильно напечатаю значение с помощью echo, я не l oop in_array: in_array () ожидает, что параметр 2 будет массивом, а значение NULL дано в .....
работает тот же цикл foreach, вставленный в тестовый файл (номера вводятся вручную) !!!