0

I have a form and I am using AJAX when user clicks on submit button. In AJAX related PHP page I have used $_POST (with out specifying the related values) .

This is working fine. But now I have implemented one bootstrap dialog box popup on that form. Now from my post method I am getting values from the dialog box also. This leads me into problem.The values are coming from bootstrap modal are dynamic values. Here is my post array.

Array(
[start_val] => 0
[accept-82RUFA55] => Array
(
    [0] => 4046228181417
    [1] => 4046228181448
    [2] => 331800000221
)

[hidden_order_id244] => 82RUFA55
[asin244] => 331800000221
[accept-82RUFA54] => Array
(
    [0] => 4046228181417
    [1] => 4046228181448
    [2] => 331800000221
)

[hidden_order_id239] => 82RUFA54
[asin239] => 331800000221
[accept-82RUFA53] => Array
(
    [0] => 4046228181417
    [1] => 4046228181448
    [2] => 331800000221
)

)

But my desired Array should be like below.

Array
(
[start_val] => 0
[accept-82RUFA55] => Array
(
    [0] => 4046228181417
    [1] => 4046228181448
    [2] => 331800000221
)
[accept-82RUFA54] => Array
(
    [0] => 4046228181417
    [1] => 4046228181448
    [2] => 331800000221
)
[accept-82RUFA53] => Array
(
    [0] => 4046228181417
    [1] => 4046228181448
    [2] => 331800000221
)

)

In array elements to hidden_order_id and asin I am concatenating the unique id.

This id is dynamic one. So I want to delete those elements from Array. So how to remove those values from my array ? Any help would be greatly appreciated.

1
  • “Now from my post method I am getting values from the dialog box also. This leads me into problem.” - why/how? If you do not want to get values from the modal - then why did you integrate it into the form in the first place? Commented Aug 2, 2019 at 12:35

2 Answers 2

2

You can get keys to delete by preg_grep on keys of input array

$keys = preg_grep('~^(asin\d+|hidden_order_id\d+)~', array_keys($input));
foreach($keys as $key) {
   unset($input[$key]);
}
Sign up to request clarification or add additional context in comments.

1 Comment

Thanks a lot @splash58. This is working like charm. You made my day.
0

Something like this should do the trick:

for ($i=0; $i < $max_dynamic_id; $i++) { 
    unset($arr['hidden_order_id' . $i]);
    unset($arr['asin' . $i]);
}

Please, let me know if this doesn't suit your case with the reason and I will modify the answer.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.