Answers for "if object key exists php"

PHP
7

php key exists

// Here's our fruity array
$fruits = ['apple', 'pear', 'banana'];

// Use it in an `if` statement
if (array_key_exists("banana", $fruits)) {
 // Do stuff because `banana` exists
}

// Store it for later use
$exists = array_key_exists("peach", $fruits);
Posted by: Guest on May-14-2020
1

array key exists in php

<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <?php
    if (array_key_exists('btn1', $_POST)) {
        button1();
    }
    if (array_key_exists('btn2', $_POST)) {
        button2();
    }
    function button1()
    {
        echo 'btn1 is clicked boom!';
    }
    function button2()
    {
        echo 'btn2 is clicked wohoo!';
    }
    ?>
    <br><br>

    <form action="" method="post">
        <button name="btn1">click here</button>
        <button name="btn2">click here</button>
    </form>
</body>
</html>
Posted by: Guest on September-10-2021

Browse Popular Code Answers by Language