Php array delete mobile value operation instance

Source: Internet
Author: User
In this tutorial, the array_slicearray_searcharray_shiftarray_uniquearray_unshift function is used as an example. * $ inputarray (& quot; a & quot;, & quot;

This tutorial mainly uses the application instances of the array_slice array_search array_shift array_unique array_unshift functions.

  1. */
  2. $ Input = array ("a", "B", "c", "d", "e"); // defines the original array
  3. $ Output = array_slice ($ input, 2); // return "c", "d", and "e"
  4. $ Output = array_slice ($ input,-2, 1); // return "d"
  5. $ Output = array_slice ($ input,); // return "a", "B", and, "c"
  6. Print_r (array_slice ($ input, 2,-1); // return c, d without retaining the key name
  7. Print_r (array_slice ($ input, 2,-1, true); // returns the reserved key names of c and d.
  8. //
  9. $ Array = array ('blue', 'red', 'green', 'red'); // defines the original array
  10. $ Key = array_search ('green', $ array); // search for green and return 2;
  11. Echo $ key;
  12. Echo"
    ";
  13. $ Key = array_search ('red', $ array); // search for red to return key 1 of the first red
  14. Echo $ key;
  15. //
  16. $ Array = array ("orange", "banana", "apple", "raspberry"); // defines the initial array
  17. $ Result = array_shift ($ array); // remove
  18. Print_r ($ result); // display the pop-up element
  19. Echo"
    ";
  20. Print_r ($ array );
  21. //
  22. $ Input = array ("a" => "green", "red", "B" => "green", "blue", "red "); // define the original array
  23. $ Result = array_unique ($ input); // perform the remove operation.
  24. Print_r ($ result );
  25. //
  26. $ Array = array ("orange", "banana"); // defines the original array
  27. $ Result = array_unshift ($ array, "apple", "raspberry"); // execute the insert operation.
  28. Print_r ($ result); // display the result
  29. Echo"
    ";
  30. Print_r ($ array );

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.