Jump to content

Using the Key of one array to search another and make use of it's value.


Recommended Posts

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?

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.