Hocam for döngüsünün hemen üstüne count etmeyi unutmuşsunuz

$count = count($pins);
For döngüsünün üstüne bunu ekleyin.