I have two arrays.
Example of the first array:
$arrayOne = array ( 'fruit' => array( 'apples' => array(), 'oranges' => array(), 'bananas' => array() ), 'vegetables' => array( 'tomatoes' => array(), 'carrots' => array(), 'celery' => array(), 'beets' => array ( 'bears' => array(), 'battlestar-galactica' => array() ), ), 'meat' => array(), 'other' => array() );
2nd:
$arrayTwo = array ( 'frewt' => array( 'aplz' => array(), 'orangeez' => array(), 'bunanahs' => array() ), 'vetchteblz' => array( 'toem8ohs' => array(), 'careodds' => array(), 'sell-R-e' => array(), 'beats' => array ( 'bare z' => array(), 'tablestar-neglectia' => array() ), ), 'neat' => array(), 'mother' => array() );
Notice that the two arrays are in the exact same "format" (same number of dimensions, number of keys, order, etc., etc.), only the names of the keys differ. (The array keys basically hold all the data.)
I have a few variables that address the keys of the first array ($arrayOne
). E.g. $one
would address the first dimension of the first array, so it's value (string) would be one out of 'fruit'
, 'vegetables'
, 'meat'
or 'other'
.
$two
would be 'apples'
or 'oranges'
or 'bananas'
or 'tomatoes'
or 'carrots'
, etc., you get the idea. (There's vars for each dimension)
As I said, those variables only address $arrayOne
. I want to be able to address the keys in the second array too, though. Meaning, by looking at the value of $one
I want to be able to get the array_key of both arrays.
gives:
You can feed the result of
getPosition
togetElementKey
:Check out array_keys from both arrays and then map the positions. Like array_keys for your arrays will give you -
Then a $arrayKeyTwo[array_search($one, $arrayKeyOne)] shuld give you what you want. Let know if this helps.