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.
- */
- $ Input = array ("a", "B", "c", "d", "e"); // defines the original array
- $ Output = array_slice ($ input, 2); // return "c", "d", and "e"
- $ Output = array_slice ($ input,-2, 1); // return "d"
- $ Output = array_slice ($ input,); // return "a", "B", and, "c"
- Print_r (array_slice ($ input, 2,-1); // return c, d without retaining the key name
- Print_r (array_slice ($ input, 2,-1, true); // returns the reserved key names of c and d.
- //
- $ Array = array ('blue', 'red', 'green', 'red'); // defines the original array
- $ Key = array_search ('green', $ array); // search for green and return 2;
- Echo $ key;
- Echo"
";
- $ Key = array_search ('red', $ array); // search for red to return key 1 of the first red
- Echo $ key;
- //
- $ Array = array ("orange", "banana", "apple", "raspberry"); // defines the initial array
- $ Result = array_shift ($ array); // remove
- Print_r ($ result); // display the pop-up element
- Echo"
";
- Print_r ($ array );
- //
- $ Input = array ("a" => "green", "red", "B" => "green", "blue", "red "); // define the original array
- $ Result = array_unique ($ input); // perform the remove operation.
- Print_r ($ result );
- //
- $ Array = array ("orange", "banana"); // defines the original array
- $ Result = array_unshift ($ array, "apple", "raspberry"); // execute the insert operation.
- Print_r ($ result); // display the result
- Echo"
";
- Print_r ($ array );