Home > front end >  How to delete all the values from the mixed array in php?
How to delete all the values from the mixed array in php?

Time:02-01

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

CodePudding user response:

It's a bit unclear what you're doing here (myArray() looks like a method, I'm not sure why, is it a method returning an array?... Pls make it a bit clearer), but if I understand correctly, you just need the array to have zero elements, so assigning an empty array would be the easiest:

$myArray = [];

If this is not the answer, let's refine the question :) You may want to include the other class (or a minimal relevant part of it) to help others understand what's going on.

CodePudding user response:

$myArray=['id','name'=>'=','address'=> 
['home'=>'dummydata','ofc'=>'ffff'],'status']; //declared in another class
$this->repository->myArray();
foreach($this->repository->myArray() as $index){
   unset($myArray[$index]);
}

use this on your code.

  •  Tags:  
  • Related