[英]PHP - isolating element(s) with same key in seemingly complicated array
I have 1 single variable $input_args
which seems to contain multiple arrays (multidimensional?): 我有1个单个变量
$input_args
,其中似乎包含多个数组(多维?):
Array ( [required] => 1 [html_label_text] => What is your gender? [required_validation_error_message] => Please enter your gender [html_name] => ee_reg_qstn[356][17] [html_id] => ee-reg-qstn [default] => Male )
Array([required] => 1 [html_label_text] =>您的性别是什么?[required_validation_error_message] =>请输入您的性别[html_name] => ee_reg_qstn [356] [17] [html_id] => ee-reg-qstn [默认值] => 男 )
Array ( [required] => 1 [html_label_text] => Favorite color? [required_validation_error_message] => Oops! Looks like something is missing [html_name] => ee_reg_qstn[356][12] [html_id] => ee-reg-qstn [default] => Blue )
Array([required] => 1 [html_label_text] =>最喜欢的颜色?[required_validation_error_message] =>糟糕!看起来好像缺少了一些东西[html_name] => ee_reg_qstn [356] [12] [html_id] => ee-reg-qstn [默认] => 蓝色 )
Array ( [required] => 1 [html_label_text] => What is your weight? [required_validation_error_message] => Enter your weight [html_name] => ee_reg_qstn[356][18] [html_id] => ee-reg-qstn [default] => 144 )
Array([required] => 1 [html_label_text] =>您的体重是多少?[required_validation_error_message] =>输入体重[html_name] => ee_reg_qstn [356] [18] [html_id] => ee-reg-qstn [默认] => 144 )
I want to isolate the different values corresponding to the [default]
key in $input_args
but I cannot seem to do it. 我想隔离与
$input_args
的[default]
键相对应的不同值,但似乎无法做到这一点。 Echoing $input_args['default']
yields all the values ie MaleBlue144
, but try to select the values individually seem to be setting the value lengths $input_args['default'][0]
yields MB1
. 回显
$input_args['default']
产生所有值,即MaleBlue144
,但是尝试单独选择这些值似乎是在设置值长度$input_args['default'][0]
产生MB1
。
I am a php novice. 我是php新手。 Thanks in advance for helping!
在此先感谢您的帮助!
edit: this is the exact array(s) upon doing var_export
编辑:这是执行
var_export
时的精确数组
array ( 'required' => true, 'html_label_text' => 'What is your gender?', 'required_validation_error_message' => 'Please enter your gender', 'html_name' => 'ee_reg_qstn[376][17]', 'html_id' => 'ee_reg_qstn-376-17', 'html_class' => 'ee-reg-qstn ee-reg-qstn-17', 'html_label_id' => 'ee_reg_qstn-376-17-lbl', 'html_label_class' => 'ee-reg-qstn', 'default' => 'Male', )array ( 'required' => true, 'html_label_text' => 'What is your color?', 'required_validation_error_message' => 'Oops! Looks like something is missing', 'html_name' => 'ee_reg_qstn[376][12]', 'html_id' => 'ee_reg_qstn-376-12', 'html_class' => 'ee-reg-qstn ee-reg-qstn-12', 'html_label_id' => 'ee_reg_qstn-376-12-lbl', 'html_label_class' => 'ee-reg-qstn', 'default' => 'Brown', )array ( 'required' => true, 'html_label_text' => 'What is your weight?', 'required_validation_error_message' => 'Enter the weight you will be', 'html_name' => 'ee_reg_qstn[376][18]', 'html_id' => 'ee_reg_qstn-376-18', 'html_class' => 'ee-reg-qstn ee-reg-qstn-18', 'html_label_id' => 'ee_reg_qstn-376-18-lbl', 'html_label_class' => 'ee-reg-qstn', 'default' => '111', )array ( 'required' => true, 'html_label_text' => 'What is you academy name?', 'required_validation_error_message' => 'If none, type "Independent"', 'html_name' => 'ee_reg_qstn[376][13]', 'html_id' => 'ee_reg_qstn-376-13', 'html_class' => 'ee-reg-qstn ee-reg-qstn-13', 'html_label_id' => 'ee_reg_qstn-376-13-lbl', 'html_label_class' => 'ee-reg-qstn', 'validation_strategies' => array ( 0 => EE_Max_Length_Validation_Strategy::__set_state(array( '_max_length' => INF, '_validation_error_message' => 'Input is too long. Maximum number of characters is INF', '_input' => NULL, )), ), 'default' => 'Inception', )array ( 'required' => true, 'html_label_text' => 'What is your team name?', 'required_validation_error_message' => 'If none, type "Independent"', 'html_name' => 'ee_reg_qstn[376][14]', 'html_id' => 'ee_reg_qstn-376-14', 'html_class' => 'ee-reg-qstn ee-reg-qstn-14', 'html_label_id' => 'ee_reg_qstn-376-14-lbl', 'html_label_class' => 'ee-reg-qstn', 'validation_strategies' => array ( 0 => EE_Max_Length_Validation_Strategy::__set_state(array( '_max_length' => INF, '_validation_error_message' => 'Input is too long. Maximum number of characters is INF', '_input' => NULL, )), ), 'default' => 'VS All Stars', )array ( 'required' => false, 'html_label_text' => 'I don\'t want to be matched with opposite gender', 'required_validation_error_message' => '', 'html_name' => 'ee_reg_qstn[376][15]', 'html_id' => 'ee_reg_qstn-376-15', 'html_class' => 'ee-reg-qstn ee-reg-qstn-15', 'html_label_id' => 'ee_reg_qstn-376-15-lbl', 'html_label_class' => 'ee-reg-qstn', 'default' => array ( ), )
If you want all the values from the default key, you might use array_column and specify default as the column key. 如果要使用默认键的所有值,则可以使用array_column并将default指定为列键。
print_r(array_column($input_args, "default"));
Result 结果
Array
(
[0] => ** **Male**
[1] => ** **Blue**
[2] => ** **144**
)
If you perhaps have unique data that can form an array key, you might specify a third parameter. 如果您可能具有可以构成数组键的唯一数据,则可以指定第三个参数。 For example:
例如:
array_column($input_args, "default", "html_name")
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.