I have one array which is mixedtype both associative and indexed based elements, i want to remove all the values and keys from the array and make that array as empty,i tried unset function but it's not removing last element of the array, can you suggest some other efficient ways.
$myArray=['id','name'=>'=','address'=>['home'=>'dummydata','ofc'=>'ffff'],'status']; //declared in another class
$this->repository->myArray();
foreach($this->repository->myArray() as $key =>$value){
unset($key);
unset($value);
}
i want to make an array empty $myArray
is declared in parent class i want to make the myArray
empty
My Answer:
You can use the `array_splice()` function to remove all elements from the array. Here's an example:
php
$myArray=['id','name'=>'=','address'=>['home'=>'dummydata','ofc'=>'ffff'],'status'];
array_splice($myArray, 0);
print_r($myArray); // Output: Array()
This will remove all elements from the array and make it empty.
Rate this post
4 of 5 based on 4545 votesComments