Mistři v programování na #hovnokod

pretoze spocitat array sa vyplati

$announcementData = array();
$announcementData["totalRecords"] = count($announcementData);
$announcementData[] = $this->repository->getAllAnnouncements();

Sebastian Simko,

Protože forcykly jsou moc mainstream.

public function generateHash()
{
    $end = false;
    $j = 0;
    $generator = new TokenGenerator();
    do {
        $hash = $generator->generate(16);
        if ($this->preregistrationRepository->findByHash($hash) == null) {
            $end = true;
        } else {
            $j++;
        }

            // break kvuli zacykleni
        if ($j > 20) {
            throw new \Exception("Preregistrace se nezdařila vytvořit - Nepodařilo se vygenerovat unikátní hash.");
        }
    } while (!$end);
    return $hash;
}

Třešťák Huho,

Není důvod, aby nativní metody měly stejné parametry ve stejném pořadí, že? :)

in_array( $needle, $haystack );
strpos( $haystack, $needle );

Marek Dočekal,

Krasna pyramida

if ($predvypln_pocet_kin == 1) {
            $nahrad["{test}"] = $table_test1;
        } elseif ($predvypln_pocet_kin == 2) {
            $nahrad["{test}"] = $table_test1 . $table_test2;
        } elseif ($predvypln_pocet_kin == 3) {
            $nahrad["{test}"] = $table_test1 . $table_test2 . $table_test3;
        } elseif ($predvypln_pocet_kin == 4) {
            $nahrad["{test}"] = $table_test1 . $table_test2 . $table_test3 . $table_test4;
        } elseif ($predvypln_pocet_kin == 5) {
            $nahrad["{test}"] = $table_test1 . $table_test2 . $table_test3 . $table_test4 . $table_test5;
        } elseif ($predvypln_pocet_kin == 6) {
            $nahrad["{test}"] = $table_test1 . $table_test2 . $table_test3 . $table_test4 . $table_test5 . $table_test6;
        } elseif ($predvypln_pocet_kin == 7) {
            $nahrad["{test}"] = $table_test1 . $table_test2 . $table_test3 . $table_test4 . $table_test5 . $table_test6 . $table_test7;
        } elseif ($predvypln_pocet_kin == 8) {
            $nahrad["{test}"] = $table_test1 . $table_test2 . $table_test3 . $table_test4 . $table_test5 . $table_test6 . $table_test7 . $table_test8;
        } elseif ($predvypln_pocet_kin == 9) {
            $nahrad["{test}"] = $table_test1 . $table_test2 . $table_test3 . $table_test4 . $table_test5 . $table_test6 . $table_test7 . $table_test8 . $table_test9;
        } elseif ($predvypln_pocet_kin == 10) {
            $nahrad["{test}"] = $table_test1 . $table_test2 . $table_test3 . $table_test4 . $table_test5 . $table_test6 . $table_test7 . $table_test8 . $table_test9 . $table_test10;
        } elseif ($predvypln_pocet_kin == 11) {
            $nahrad["{test}"] = $table_test1 . $table_test2 . $table_test3 . $table_test4 . $table_test5 . $table_test6 . $table_test7 . $table_test8 . $table_test9 . $table_test10 . $table_test11;
        } elseif ($predvypln_pocet_kin == 12) {
            $nahrad["{test}"] = $table_test1 . $table_test2 . $table_test3 . $table_test4 . $table_test5 . $table_test6 . $table_test7 . $table_test8 . $table_test9 . $table_test10 . $table_test11 . $table_test12;
        } elseif ($predvypln_pocet_kin == 13) {
            $nahrad["{test}"] = $table_test1 . $table_test2 . $table_test3 . $table_test4 . $table_test5 . $table_test6 . $table_test7 . $table_test8 . $table_test9 . $table_test10 . $table_test11 . $table_test12 . $table_test13;
        } elseif ($predvypln_pocet_kin == 14) {
            $nahrad["{test}"] = $table_test1 . $table_test2 . $table_test3 . $table_test4 . $table_test5 . $table_test6 . $table_test7 . $table_test8 . $table_test9 . $table_test10 . $table_test11 . $table_test12 . $table_test13 . $table_test14;
        } elseif ($predvypln_pocet_kin == 15) {
            $nahrad["{test}"] = $table_test1 . $table_test2 . $table_test3 . $table_test4 . $table_test5 . $table_test6 . $table_test7 . $table_test8 . $table_test9 . $table_test10 . $table_test11 . $table_test12 . $table_test13 . $table_test14 . $table_test15;
        } elseif ($predvypln_pocet_kin == 16) {
            $nahrad["{test}"] = $table_test1 . $table_test2 . $table_test3 . $table_test4 . $table_test5 . $table_test6 . $table_test7 . $table_test8 . $table_test9 . $table_test10 . $table_test11 . $table_test12 . $table_test13 . $table_test14 . $table_test15 . $table_test16;
        } elseif ($predvypln_pocet_kin == 17) {
            $nahrad["{test}"] = $table_test1 . $table_test2 . $table_test3 . $table_test4 . $table_test5 . $table_test6 . $table_test7 . $table_test8 . $table_test9 . $table_test10 . $table_test11 . $table_test12 . $table_test13 . $table_test14 . $table_test15 . $table_test16 . $table_test17;
        } else {
        }

Anonymous,

Aneb když po kolegovi debugujete proč NULL z SQL leze do ToDo #2 Kód byl záměrně vyčištěn k zachování firemní politiky. PS: Zabiju ho!

$sql = "SELECT * FROM table WHERE id='".$value."";
$data = mysqli_query($link, $sql);
while($row = mysqli_fetch_assoc($data)){
    if($row['key']==""){
        //ToDo #1
    }else{
        //ToDo #2
    }
}

Anonymous,