也許我的問題的類型不太清楚,但我不知道解釋我需要的更好方法。這裏是我在WordPress的一些自定義頁面上工作的東西,我有一個數組中的輸入字段。該數組中的輸入字段與第二個數組的id匹配,但實際上我需要獲得與第一個數組的id相匹配的第二個數組的類型字段。通過將第二個數組的密鑰ID與第一個數組的密鑰ID進行匹配來查找第二個數組的密鑰類型
這裏是第一陣列的示例
$first_array = array(
'sample_text' => 'some text here',
'sample_textarea' => 'some text here in textarea field',
'sample_upload' => 'http://somelink.com/someimage.jpg'
);
這裏是第二陣列。
$second_array = array(
array(
'type' => 'upload',
'id' => 'sample_upload',
'title' => 'Sample upload button'
),
array(
'type' => 'textfield',
'id' => 'sample_text',
'title' => 'Sample text field'
),
array(
'type' => 'textarea',
'id' => 'sample_textarea',
'title' => 'Sample textarea field'
),
);
所以基本上在第二陣列中首先用於產生在前端的輸入字段,但在形式提交表單提交的陣列,其看起來像第一示例中,所以現在第一陣列上我需要循環爲每個輸入和匹配第二個和第一個數組的id,但是當id匹配時,我需要輸入類型字段並應用該類型字段名稱的篩選器。
所以基本上
// loop through inputs in the array
foreach($first_array as $key => $value) {
// Now the first $key would be 'sample_text'
// How to search $second_array for 'id' with 'sample_text'
// And if that 'id' exists, take the 'type' field and apply filter named same as that 'type' field
}
但我不知道究竟我怎麼會通過第二陣列和環獲得基於「身份證」「型」
所以,你想第一個是第二個的索引? – weirdpanda
如果這可行,我不知道,我已閱讀php.net,它看起來像這不是我想要的 –