To determine the position of an array element, we can use the array_keys function to compare with foreach to implement the syntax of array_keys as follows: array_keys (array, value, [strict]) where strict settings
To determine the position of an array element, we can use the array_keys function to compare with foreach.
The syntax of array_keys is as follows:
Array_keys (array, value, [strict])
When strict is set to true, the strict matching mode of data type verification is triggered. the default value is false. the following code shows a simple application of array_keys. the code is as follows:
- $ Test = array (10, 20, 30, "10", "20", "30 ");
- Print_r (array_keys ($ test, "10", true); // exact match
- // Output:
- // Array ([0] => 3)
- ?>
Of course, we can also use foreach to judge, the code is as follows:
- $ One = array (1, 2, 3, 4 );
- $ Two = array ("test1" => array ('name' => "tank", "phone" => 12412433 ),
- "Test2" => array ('name' => "ying", "phone" => 252523523 ),
- "Test3" => array ('name' => "zhang", "phone" => 656452345 ),);
- Foreach ($ one as $ k => $ v ){
- Echo "key =". $ k. "& value =". $ v ."
";
- }
- $ I = 0;
- Foreach ($ two as $ k => $ v ){
- Foreach ($ v as $ value ){
- If ($ v = 'tank ')
- {
- Echo $ I;
- }
- $ I ++;
- }
- }
Next, we can use the traversal of the array and then compare the result by adding a value.