Php method to insert an array without affecting the original sequence _ PHP Tutorial

Source: Internet
Author: User
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...

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.