Parameter Requirement Description value Required Specifies the value whose key|index we are searching. Return value: The index or key of the array element matching the value. This works only when the array has one instance of that value. We then use the found key or index in the same way as in the examples above. In the scenario where we already know an array element value but not its index or key we can update it by first getting its key|index using the array_search() function. We used the key 'name' to update its value from 'Kenya' to 'Nigeria'. "Kenya", "continent" => "Africa") Įcho "Array before updating an element value: " Īrray before updating name element value: Updating the value of an associative array element. You can see that before and after updating the array, the value of array index 3 has changed from "Nissan" to "Volvo". We used its index to update the array and assigned it a new value "Volvo". In the above example, we had Nissan as the fourth element and index 3. " Įcho "Array after updating fourth element value: " Īrray after updating fourth element value: Updating the value of an indexed array element. value This is the value to be assigned to the array element to replace the old value. A key is a string value that identifies an element in an associative array. The index is an integer value that identifies an element in an indexed array. It can be an index or a key depending on the array type. index|key This specifies the element to be updated in the array. Parameter Description Array-Variable This is the name of the variable containing the array to be updated.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |