I want to delete some data from an array in PHP. Here is the array:
array(4) {
[0]=> array(1) { ["image"]=> string(20) "w85YrKChBGTZ9fQS.jpg" }
[1]=> array(1) { ["image"]=> string(20) "3buahEs6rRWFdYez.jpg" }
[2]=> array(1) { ["image"]=> string(20) "gYPtDrx3sFzkVENB.jpg" }
[3]=> array(1) { ["image"]=> string(20) "JE3rodDvs6521cFm.jpg" }
}
Here is my method and where I am deleting:
public function deleteImage(){
foreach (getCarImages() as $array){
//var_dump($array).'<br>';
$index = array_search('w85YrKChBGTZ9fQS.jpg',$array);
if($index !== FALSE){
var_dump($index).'<br>';
unset($array[$index]);
}else{
echo '<br>else here';
}
}
}
And here is the result of deleteImage()
string(5) "image"
else
here
else
here
else
here
I am confused. How can I delete a nested array from the main array.
if($index). if item not found thenarray_searchreturn empty.getCarImages()function. What isdeleteImage()actually going to do? Is there a return value? A file function? A database query?