PHP - 通过输入字段搜索PHP数组?

<?php
$allBookings = [
    "IMD002" => [
        "client" => "James Holden",
        "paid"   => "yes",
        "email"  => "james.holden@gmail.com"
    ],
    "IMD003" => [
        "client" => "Harold P. Redman",
        "paid"   => "yes",
        "email"  => "HaroldPRedman@dayrep.com"
    ],
    "IMD004" => [
        "client" => "Marcus C. Nelson",
        "paid"   => "no",
        "email"  => "MarcusCNelson@armyspy.com"
    ]
];


// DONT EDIT ANYTHING BELOW HERE
if(!empty($_POST)) {
    $clientName = $booking['client'];
}
else {
    $clientName = null;
};
?>

<!-- DONT EDIT ANYTHING BELOW HERE -->
<div class="myApp">
    <form method="post">
        <input type="text" name="bookingReference" placeholder="Booking Reference">
        <input type="submit" value="Find Client">
    </form>
    
    <h2 id="result_name">Client name: <em><?php echo $clientName; ?></em></h2>
    
</div>

How can I showup the credentials when I type into the input field (booking reference) for example "IMD002"? As it should show up the array listed in php under "IMD002". I'm assuming its something to do with a $_POST statement?

Thanks alot

</div>

After $allBookings = [ ... ]

Try adding something like :

if(isset($_POST['bookingReference']) &&
   isset($allBookings[$_POST['bookingReference']])) {
    $booking = $allBookings[$_POST['bookingReference']];
}
else {
    $booking = ['client' => 'Invalid Ref/Not found'];
};

To search, Use $_POST['bookingReference'] as index to, $allBookings, your data array;

Try:

$allBookings[$_POST['bookingReference']];

Print the content:

print_r( $allBookings[$_POST['bookingReference']] );