Using the array below, I want to get just some value of an element containing a certain value for option_name. For example, I want to get the element with option_name => custom_radio_gender then the result will show the value of option_value for that element (i.e. Radio 1).
Array
(
[0] => Array
(
[ID] => 15
[user_id] => 3
[option_name] => custom_monStart
[option_value] => a:3:{i:0;s:8:"05:30 am";i:1;s:8:"07:30 am";i:2;s:8:"09:30 am";}
[autoload] => yes
)
[1] => Array
(
[ID] => 13
[user_id] => 3
[option_name] => custom_radio_gender
[option_value] => Radio 1
[autoload] => yes
)
[2] => Array
(
[ID] => 14
[user_id] => 3
[option_name] => custom_time2
[option_value] =>
[autoload] => yes
)
)
It's a basic PHP question,which has nothing relationship with javascript.What you need is just a function like:
function getValue($array, $key){
foreach($array as $content){
if(array_key_exists("option_name", $content) && $content["option_name"] == $key){
return $content["option_value"];
}
}
}
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments