Answer the question
In order to leave comments, you need to log in
Only the check element of the array is removed, and the rest are not?
Hello! Please tell me what I'm doing wrong and how to do it better. There is a while loop, and there is an array in it, and I need to delete the i-th element of the array with data.
if($tree['status'][$i]=='pending')
{
unset($tree['status'][$i]); - the element is removed
unset($tree['currency'][$i]) - remains(, but it is necessary that it also be removed;
}
Answer the question
In order to leave comments, you need to log in
You need to change the logic of the program.
At least use not $tree['status'][$i] and $tree['currency'][$i], but $tree[$i]['status'] and $tree[$i]['currency '].
In this case, removal is easier.
Further, removing an element from the array through unset, the numbering remains.
That is, if from $a = array(11, 22, 33, 44, 55); remove unset($a[0]), then 22, 33, 44, 55 will remain in the array, but their indices will not be 0 - 3, but 1 - 4. Array_values is used to rearrange arrays.
Most likely everything is deleted for you, but due to such side effects of deletion, you do not notice it.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question