I did a array with some things in it and it works just perfect! now i returned the array to my view (the html) and want to use it in my html.. but it gives me this error message:
Undefined offset: 2 (View: /path/data.blade.php)
but I can't see why.. in my controller it's all fine.. the array works perfectly and in my returning to the html is no mistake too (at least I can't see one)
$ipsWithBytesDates = [];
foreach ($topTenIp as $val)
{
$byte_execResult = shell_exec("grep $val /path/domain.log | awk '{print $10}'");
$add = array_sum(explode("
", $byte_execResult));
$add = $add / 1024 / 1024;
$add = round($add, 2);
$date_execResult = shell_exec("grep $val /path/domain.log | awk '{print $4,$5}'");
$date_array = explode("
", $date_execResult);
$date_array_pop = array_pop($date_array);
$mylastelement = end($date_array);
$ipsWithBytesDates[] = [
'ip' => $val,
'bytes' => $add,
'dates' => $mylastelement,
];
}
uasort($ipsWithBytesDates, function($a, $b) {
if ($a['bytes'] == $b['bytes'])
return 0;
elseif ($a['bytes'] < $b['bytes'])
return 1;
else
return -1;
});
uasort($ipsWithBytesDates, function($a, $b) {
if ($a['dates'] == $b['dates'])
return 0;
elseif ($a['dates'] < $b['dates'])
return 1;
else
return -1;
});
I'm returning the variable like this:
return view('/domains/data', [
'ipsWithBytesDates' => $ipsWithBytesDates,
]);
and my html looks like this:
@foreach($ipsWithBytesDates as $item)
<tr>
<td>{{ $item['ip'] }}</td>
<td>{{ $item['bytes'] }}</td>
<td> {{ $item['dates'] }}</td>
</tr>
@endforeach
I really can't find the mistake... I'm stuck, could anybody look over my code and maybe find with me the mistake?