は、私はこのように見えるかもしれ配列を持っている:
Array
(
[action] => remove
[data] => Array
(
[row_1] => Array
(
[DT_RowId] => row_1
[name] => Unit 1
[item_price] => 150.00
[active] => Y
[taxable] => Y
[company_id] => 1
)
)
)
row_1値がrow_ようにフォーマットは何もすることができますか?
数字が何であれ、その数字を文字列として入力します。そのキーとDT_RowIDの値は、それが役に立つ場合は常に同じ値になります。
は、今のところ私はこれをやっているが、それはそれを行うための悪い方法のように思える:
//the POST is a multidimensinal array... the key inside the 'data' array has the id in it, like this: row_2. I'm getting the key value here and then removing the letters to get only the id nummber.
foreach ($_POST['data'] AS $key => $value) {
$id_from_row_value = $key;
}
//get only number from key = still returning an array
preg_match_all('!\d+!', $id_from_row_value, $just_id);
//found I had to use [0][0] since it's still a multidimensional array to get the id value
$id = $just_id[0][0];
それは動作しますが、私は$ _POST配列からその数を取得するより高速な方法があります推測しています。
foreachループの代わりに 'array_keys()'を使ってキーを取得することができます。それでは、 'preg_match_all()'の代わりに 'preg_match()'を使って数字だけを得ることができます。 – Rizier123
ボトムコードの問題点の1つは、 '$ _POST ['data']'に複数の行がある場合、ループ '$ id_from_row_value'の各反復がそのキーの値を再割り当てされているので、 。 –