October 9th, 2013, 11:05 AM
Associative array, find key, echo value. Stuck.
I am trying to capture a value through an HTML form, but I cannot understand why the value from the array isn't being echo on the screen.
All I want to do is search the array keys for a match, and then echo/print the matching value to the screen. Cannot find a built in function for it :-(
Can you why it isn't working?
$myarray['a'] = 'string one';
$myarray['ab'] = 'string two';
$myarray['abc'] = 'string three';
<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post">
Name: <input type="text" name="name">
$findme = $_POST['name'];
Thanks for any help : - )
October 9th, 2013, 11:09 AM
October 13th, 2013, 10:43 AM
Don't understand what you are saying Jacques.
Can anyone help me with this? Still stuck.
October 13th, 2013, 11:32 AM
You said you want the array value for a given key, right? Well, that's simply
If that's not what you want, you have to be more specific. What's the result you want to see on the screen?
Comments on this post
October 13th, 2013, 11:50 AM
Thank you for your help Jacques, thats what I wanted and it's working now.
Originally Posted by Jacques1
October 13th, 2013, 02:01 PM
Note that you'll want to wrap that in an isset() check to prevent E_NOTICE errors in the event someone entered a key that does not exist in the array.
echo isset($myarray[$findme])?$myarray[$findme]:'Not found';
Recycle your old CD's, don't just trash them
If I helped you out, show some love with some reputation, or tip with Bitcoins to 1N645HfYf63UbcvxajLKiSKpYHAq2Zxud