Promo Member Baru 40%! Program Full Stack Membership! Hanya 3 Hari! Klaim Promo

Error Future Version of PHP

Ditanyakan pada tanggal 12 February 2020 oleh Yohanes Setiawan
<?php
$nama_depan = "Yohanes ";
$nama_belakang = "Setiawan";
$nama_lengkap = $nama_depan . $nama_belakang;
$variabel = 'variabel $nama_lengkap';
?>
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Latihan PHP1</title>
</head>
<body>
    <h1>Selamat datang di website <?php echo $nama_lengkap ?></h1> <br>
    <p>Tag ini tidak dapat digunakan di PHP karena <?php echo $variabel?> muncul </p> <br>
    <p>Ini contoh output PHP array</p> <br>
    <?php
    //Variabel wajib pakai dollar ($)
        $angka  = array(1,2,3,4,5); //kumpulan data integer
        $buah   = ["pisang","anggur","apel","kiwi","nanas"]; //kumpulan data string
        //tuliskan nama array dan nomor index yang akan diubah, lalu isi dengan data baru
        $angka[3]   = 99;  
        $buah[2]    = "strawberry";
        $buah[]     = "durian"; //append array
        var_dump($angka);
        echo "<br>";
        var_dump($buah);
    ?>
    <p>Ini contoh output Array Asosiatif dengan foreach loop:</p> <br>
    <?php
    $alamat = array(
        "Yohanes"=>"Surabaya",
        "Danu"=>"Situbondo",
        "Yoan"=>"Bekasi"
    );
    $jenis_kelamin= array(
        24, "Laki-laki",
        24, "Laki-laki",
        24, "Perempuan"
    );
    foreach($alamat as $x => $value)
    {
        echo "Alamat " .$x. "  di " . $value;
        echo "<br>";
    } 
    for ($baris=0; $baris<2; $baris++) {
        echo "Keterangan lainnya: <br> ";
        echo "<ul>"; 
        for ($kolom=0; $kolom <2 ; $kolom++) { 
            echo "<li>".$jenis_kelamin[baris][kolom]."</li>"; 
        }
        echo "</ul>";
    }
    ?>
</body>
</html>

Output: Selamat datang di website Yohanes Setiawan

Tag ini tidak dapat digunakan di PHP karena variabel $nama_lengkap muncul

Ini contoh output PHP array

array(5) { [0]=> int(1) [1]=> int(2) [2]=> int(3) [3]=> int(99) [4]=> int(5) } array(6) { [0]=> string(6) "pisang" [1]=> string(6) "anggur" [2]=> string(10) "strawberry" [3]=> string(4) "kiwi" [4]=> string(5) "nanas" [5]=> string(6) "durian" } Ini contoh output Array Asosiatif dengan foreach loop:

Alamat Yohanes di Surabaya Alamat Danu di Situbondo Alamat Yoan di Bekasi Keterangan lainnya:

Warning: Use of undefined constant baris - assumed 'baris' (this will throw an Error in a future version of PHP) in C:\xampp\htdocs\latihanphp\lat1.php on line 51

Warning: Use of undefined constant kolom - assumed 'kolom' (this will throw an Error in a future version of PHP) in C:\xampp\htdocs\latihanphp\lat1.php on line 51

Notice: Undefined index: baris in C:\xampp\htdocs\latihanphp\lat1.php on line 51

Notice: Trying to access array offset on value of type null in C:\xampp\htdocs\latihanphp\lat1.php on line 51

Warning: Use of undefined constant baris - assumed 'baris' (this will throw an Error in a future version of PHP) in C:\xampp\htdocs\latihanphp\lat1.php on line 51

Warning: Use of undefined constant kolom - assumed 'kolom' (this will throw an Error in a future version of PHP) in C:\xampp\htdocs\latihanphp\lat1.php on line 51

Notice: Undefined index: baris in C:\xampp\htdocs\latihanphp\lat1.php on line 51

Notice: Trying to access array offset on value of type null in C:\xampp\htdocs\latihanphp\lat1.php on line 51 Keterangan lainnya:

Warning: Use of undefined constant baris - assumed 'baris' (this will throw an Error in a future version of PHP) in C:\xampp\htdocs\latihanphp\lat1.php on line 51

Warning: Use of undefined constant kolom - assumed 'kolom' (this will throw an Error in a future version of PHP) in C:\xampp\htdocs\latihanphp\lat1.php on line 51

Notice: Undefined index: baris in C:\xampp\htdocs\latihanphp\lat1.php on line 51

Notice: Trying to access array offset on value of type null in C:\xampp\htdocs\latihanphp\lat1.php on line 51

Warning: Use of undefined constant baris - assumed 'baris' (this will throw an Error in a future version of PHP) in C:\xampp\htdocs\latihanphp\lat1.php on line 51

Warning: Use of undefined constant kolom - assumed 'kolom' (this will throw an Error in a future version of PHP) in C:\xampp\htdocs\latihanphp\lat1.php on line 51

Notice: Undefined index: baris in C:\xampp\htdocs\latihanphp\lat1.php on line 51

Notice: Trying to access array offset on value of type null in C:\xampp\htdocs\latihanphp\lat1.php on line 51

1 JAWABAN / 0 KOMENTAR

User avatar
Ahmad Oriza menjawab pada tanggal 12 February 2020

Hai kak,

Dalam penulisan array assosiatif harus menggunakan string. Pada bagian ini :

 $jenis_kelamin[baris][kolom]

Harusnya begini :

 $jenis_kelamin['baris']['kolom']

Pakai petik atau kutip. Makanya dia mengeluarkan notice error.