I'm trying to add to an array in a IF condition but it's not appending although i'm in a foreach loop
what I have doesn't append to $connected but the key increments:
$key1 = '0';
foreach ($dataNewAndUnlock1 as $key => $val) {
$stream = ssh2_exec($connection, 'ping -c 1 '. $val);
stream_set_blocking($stream, true);
while ($o = fgets($stream)) {
$connected = array();
if (strpos($o, 'ttl') !== false) {
$connected[$key1] = $val;
echo $val .' EnodeB is connected <br>';
$key1++;
}
if (strpos($o, '0 received') !== false) {
echo $val .' EnodeB NOT connected <br>';
}
}
}
$connnected gives something like this, then var_dump is empty at the end
C:\wamp64\www\SendJason2.php:286: array (size=1) 0 => string 'XXX.XX.XXX.XXX' (length=14) C:\wamp64\www\SendJason2.php:286: array (size=1) 1 => string 'XXX.XX.XXX.XX' (length=13) C:\wamp64\www\SendJason2.php:286: array (size=1) 2 => string 'XXX.XX.XXX.XXX' (length=14) C:\wamp64\www\SendJason2.php:286: array (size=1) 3 => string 'XXX.XX.XXX.XXX' (length=14) C:\wamp64\www\SendJason2.php:286: array (size=1) 4 => string 'XXX.XX.XXX.XXX' (length=14) ... C:\wamp64\www\SendJason2.php:306: array (size=0) empty
$valactually pushing data out?$key1with the string0and then use$key1++?C:\wamp64\wwwfolder. Thats reserved for WAMPServer.. Make a subfolder for all your projects or better still a Virtual Host in a totally seperate folder