Following up this question, I have a further problem - I have two same sub keys, but they have different combination of array in their variant
key, for instance,
Array
(
[1] => Array
(
[b] => Array
(
[quantity_request] => 1
[time_created] => 1339688613
[variant] => Array
(
[0] => x
[1] => y
)
)
)
[2] => Array
(
[b] => Array
(
[quantity_request] => 1
[time_created] => 1339688631
[variant] => Array
(
[0] => x
[1] => z
)
)
)
[3] => Array
(
[c] => Array
(
[quantity_request] => 1
[time_created] => 1339688959
[variant] => Array
(
)
)
)
)
so, how can I find the match of this item,
[b] => Array
(
[quantity_request] => 1
[time_created] => 1339688631
[variant] => Array
(
[0] => x
[1] => z
)
)
function get_letter($letter,$array)
{
foreach($this->content as $k => $v)
{
if(array_key_exists($letter, $v))
{
return $k;
}
}
return false;
}
list($key,$different) = get_letter('b',array("x","z")); // return 1
I want the result like this if there is a match,
2
Any ideas?
You just need to add:
if ($v['variant'] == $array)
inside your if
statement to compare the variant
array with the one passed as an argument.
function get_letter($letter, $array)
{
foreach($this->content as $k => $v)
{
if(array_key_exists($letter, $v))
{
if ($v['variant'] == $array)
return $k;
}
}
return false;
}