There are arrays displayed in a loop

foreach($k as $t => $r){ $r = explode(" ", $r); print_r($r); } на экране так: Array ( [0] => 10.10.1.0 ) Array ( [0] => FF:66:00:77:FF:AB ) Array ( [0] => 7 ) Array ( [0] => 10.10.1.1 ) Array ( [0] => FF:66:00:77:FF:AС ) Array ( [0] => 8 ) Array ( [0] => 10.10.1.2 ) Array ( [0] => FF:66:00:77:FF:AD) Array ( [0] => 9 ) 

How to do it (Combine 3)

 Array( [0] => 10.10.1.0 [1] => FF:66:00:77:FF:AB [2] => 7 ) Array( [0] => 10.10.1.1 [1] => FF:66:00:77:FF:AС [2] => 8 ) Array( [0] => 10.10.1.2 [1] => FF:66:00:77:FF:AD [2] => 9 ) 
  • do you have explode always returning 1 item? why is it needed then? break the source into groups of 3 array_chunk($k, 3) - teran

1 answer 1

At you in $ r lines turn out. Why convert them to an array? It turns out you need arrays of 3 consecutive elements, if I understood

 $i = 0; $result = []; foreach($k as $t => $r){ $result[floor($i/3)][$i % 3] = $r; $i++; } 

The result is an array

 Array ( [0] => Array ( [0] => 10.10.1.0 [1] => FF:66:00:77:FF:AB [2] => 7 ) [1] => Array ( [0] => 10.10.1.1 [1] => FF:66:00:77:FF:AРЎ [2] => 8 ) [2] => Array ( [0] => 10.10.1.2 [1] => FF:66:00:77:FF:AD [2] => 9 ) ) 
  • Something is wrong with the code - Kvandaik
  • Array ([0] => Array ([0] => 10.10.1.0) [1] => Array ([0] => FF: DD: 04: 74: F3: AB) [2] => Array ([ 0] => 7)) - Kvandaik
  • and how to make now that the condition is permissible on the Mac was if (isset ($ array_1 [$ result [0 ?????]]) - Kvandaik
  • didn't understand your question - Evgeniy Belov
  • @Kvandaik do not need to ask additional questions not directly related to yours in the comments. Create a new question that you will try to answer. - u_mulder