Php deletes the comparison of the specified values in an array. You also have a function yourself. many built-in functions in the php Tutorial have problems (not an error, but the applicability is narrow) for (old array .....) {if (the value to be deleted) continue $ newArr [] each value} you are also a function. many built-in functions in the php Tutorial have problems (not an error, is applicable in a narrow range)
For (old array .....){
If (the value to be deleted)
Continue
$ NewArr [] = each value
}
Return $ newArr
Instance
Array ([0] => Hello [1] => world. [2] => It's [3] => a [4] => beautiful [5] => day .)
Foreach ($ array as $ k => $ v ){
If ($ v = 'day '){
Unset ($ array [$ k]):
}
}
Using foreach is inefficient. check the built-in functions of php.
$ Arr = array ("Hello", "world", "It's", "beautiful", "day ");
Instance 1
$ Arr = array_flip ($ arr );
Unset ($ arr ['world']);
$ Arr = array_flip ($ arr );
Print_r ($ arr );
Instance 2
The array_search () function is the same as the in_array () function. you can find a key value in the array. If this value is found, the key name of the matching element is returned. If not found, false is returned.
$ Arr = Array ([0] => Hello [1] => world. [2] => It's [3] => a [4] => beautiful [5] => day .);
If ($ key = array_search ('day', $ arr ))){
Unset ($ arr [$ key]);
}
Instance 3
The array_splice () function is similar to the array_slice () function. it selects a series of elements in the array but does not return them. Instead, it deletes them and replaces them with other values.
If ($ key = array_search ('day', $ arr ))){
Array_splice ($ arr, $ key, 1 );
}
Many built-in functions in the php Tutorial have problems (not an error, but the applicability is narrow) for (old array .....) {if (the value to be deleted) continue $ newArr [] = each value }...