PHP is still more commonly used, so I studied the PHP two-dimensional array, here to share with you, I hope that you can use PHP from the array to remove a value from the PHP built-in function array_slice (), but this function only supports one-dimensional array, For the specific use of the PHP manual, the Array_slice function does not support a two-dimensional array. First look at the Array_slice function:
- Array array_slice (array array, int offset [, int length [, bool Preserve_keys]]) array_slice ()
Returns a sequence in an array of arrays specified by the offset and length parameters.
Example: Extracting a value from a one-dimensional array
- php $arrayarray = Array (' B ', ' I ', ' u ', ' u ', ' U '); $ resultarray_slice?>
The instance takes four values from the array $array, starting at the beginning array subscript 0, and the result is as follows: extracting a value from a one-dimensional array is very simple and directly makes the built-in function Array_slice. PHP two-dimensional array of values also need to use the Array_slice function, instance two-dimensional array data as follows:
- $ Array Array = Array ();
- $array [1] = array (' 1 ' =>' B1 ', ' 2 ' =>' i1 ', ' 3 ' =>' U1 ', ' 4 ' =>' U1 ', ' 5 ' =>' U1 ');
$array [2] = array (' 1 ' =>' B2 ', ' 2 ' =>' i2 ', ' 3 ' =>' U2 ', ' 4 ' =>' U2 ', ' 5 ' =>' U2 ');
$array [3] = array (' 1 ' =>' B3 ', ' 2 ' =>' i3 ', ' 3 ' =>' U3 ', ' 4 ' =>' U3 ', ' 5 ' =>' U3 ');
$array [4] = array (' 1 ' =>' b4 ', ' 2 ' =>' I4 ', ' 3 ' =>' U4 ', ' 4 ' =>' U4 ', ' 5 ' =>' U4 ');
$array [5] = array (' 1 ' =>' b5 ', ' 2 ' =>' i5 ', ' 3 ' =>' U5 ', ' 4 ' =>' U5 ', ' 5 ' =>' U5 ');
$array [6] = array (' 1 ' =>' b6 ', ' 2 ' =>' I6 ', ' 3 ' =>' U6 ', ' 4 ' =>' U6 ', ' 5 ' =>' U6 ');
$array [7] = array (' 1 ' =>' B7 ', ' 2 ' =>' i7 ', ' 3 ' =>' U7 ', ' 4 ' =>' U7 ', ' 5 ' =>' U7 ');
As in the two-dimensional array, if you need to take out one of the paragraphs, you need to know where to start and end the position of the array, taking into account the particularity of the application, only starting from the first array, in this two-dimensional array to remove the number of required array. Here's how:
- function Array_silice_func (array $array, $limit)
- {$k = $count = 0; $temp = array< /c9> ();
- foreach ($array as $key => $value)
- {$countcount = count ($value);
- if ($count + $k >= $limit)
- {$t = array_slice ($value, 0, $limit-$k);
- $temp [$key] = $t; Break }
- $temp [$key] = $value; $k + = $count; } return $temp; }
Use the following: Print_r (Array_silice_func ($array, 5)) takes out the 5 values of the two-dimensional array, resulting in the following: Array ([1] = = Array ([0] = B1 [1] = I1 [2] =& Gt u1 [3] = u1 [4] = u1) and so on, remove the number of required arrays. Due to the limitations of the use of PHP's two-dimensional arrays, there is no need to implement a single subscript from a two-dimensional array, and the number of groups to be removed, but this is also worth exploring. The above is about how to use PHP from a two-dimensional array to remove a specified value, we hope to help.
http://www.bkjia.com/PHPjc/446526.html www.bkjia.com true http://www.bkjia.com/PHPjc/446526.html techarticle PHP is still more commonly used, so I studied the PHP two-dimensional array, here to take out and share with you, I hope that you can use PHP from the array to remove a value in PHP ...