Bjorn Pijpops Bjorn Pijpops - 25 days ago 7
PHP Question

HTTP error 500, not sure where to start

<?php
$tabel = array();
$teller = 0;
$handle = opendir(dirname(realpath(__FILE__)).'/images/bbq2015/');
while($file = readdir($handle)){
if($file !== '.' && $file !== '..'){
$tabel[$teller] = $file;
$teller++;
}
}

$n = $tabel.length();
for ($i = 0; $i < $n-1; $i++)
for ($j = 0; $j < $n-$i-1; $j++)
if ($tabel[$j] > $tabel[$j+1])
{
$temp = $tabel[$j];
$tabel[$j] = $tabel[$j+1];
$tabel[$j+1] = $temp;
}
$teller = 0;
while($teller < $n){
echo '<a class="example-image-link" href="images/bbq2015/'.$tabel[$teller].'" data-lightbox="example-set" data-title="BBQ 2015"><img class="halloween2015" src="images/bbq2015/'.$tabel[$teller].'"/></a>';
$teller++;

}
?>


I realise that this might not be the best code but I'm trying.
I would love to know where I'm making an error, not looking for my code fixed.

Answer

Change

$n= $tabel.length(); //there is no length() function in PHP

to

$n= count($tabel);

count() returns the number of elements in an array.

Comments