Php inserts an array without affecting the original sequence. Php: how to insert an array without affecting the original sequence this article mainly introduces how php inserts an array without affecting the original sequence. The example analyzes the php array operation skills, php method for inserting arrays without affecting the original order
This article describes how to insert an array in php without affecting the original sequence. The example analyzes the php array operation skills and provides some reference value. For more information, see
This example describes how php inserts an array without affecting the original sequence. Share it with you for your reference. The specific implementation method is as follows:
?
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
Function array_intsort ($ array, $ num ){ $ Array_right = $ array_left = array (); $ Length = count ($ array ); If ($ num <$ array [0]) { Array_unshift ($ array, $ num ); Return $ array; } Else { For ($ I = 0; $ I <$ length; $ I ++ ){ If ($ I + 1 <$ length ){ If ($ array [$ I] <$ num & $ num <$ array [$ I + 1]) { $ Array_right = array_slice ($ array, $ I + 1 ); $ Array_left = array_slice ($ array, 0, $ I ); $ Array_left [] = $ num; Break; } } Else { $ Array_left = $ array; $ Array_left [] = $ num; } } Return array_merge ($ array_left, $ array_right ); } } |
I hope this article will help you with php programming.
This article describes how to insert an array in php without affecting the original sequence. The example analyzes the php array operation skills and has...