NavCrowds Posted July 7 Share Posted July 7 Hi all, I am trying to search and array (neat) based on the key of another array (data) They both have identical key values but the content differs. I am basically trying to display errors for missing fields and want to be able to display what is missing in a neater way. However I am not getting any results? <?php $data = [ 'keyone' => $_POST['myvalue'], 'keytwo' => $_POST['myothervalue'], ]; $neat= [ 'keyone' => 'My Value', 'keytwo' => 'My Other Value', ]; foreach ($data as $key=>$value) { if($value == ''){ $neatdisp = array_search($key, $neat); echo ' My Neat Display is: '.$neatdisp.'<br/>'; //this should display the following // if the $_POST values are empty ///////////////////////////////// //My Neat Display is: My Value //My Neat Display is: My Other Value ////////////////////////////////// // what it is display when I test //My Neat Display is: //My Neat Display is: ///////////////////////////////// } else {} } ?> Wha'ts the best way for me to approach this? Quote Link to comment https://forums.phpfreaks.com/topic/322191-using-the-key-of-one-array-to-search-another-and-make-use-of-its-value/ Share on other sites More sharing options...
Barand Posted July 7 Share Posted July 7 1 hour ago, NavCrowds said: want to be able to display what is missing in a neater way. A neater way would be to have the $_POST keys matching the $neat keys. (EG $_POST['keyone'] and $_POST['keytwo'] Quote Link to comment https://forums.phpfreaks.com/topic/322191-using-the-key-of-one-array-to-search-another-and-make-use-of-its-value/#findComment-1629446 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.