I have an multidimensional array like this:
$downloadArray = [
"downloads1" => ["downloadnaam" => "fdgssgsfg"],
"downloads2" => ["downloadnaam" => "eyetyy"],
];
I need to check if the value eyetyy
exists in this array under the key downloadnaam
Then I need to find the index of this value and remove it from the array.
The expected result:
$downloadArray = [
"downloads1" => ["downloadnaam" => "fdgssgsfg"]
];
I tried this:
$index = array_search($download->name, array_column($downloadArray, 'downloadnaam'));
if ($index !== null)
{
unset($downloadArray[$index]);
die("found index: " . $index);
}
$download->name
contains 'eyetyy'
$downloadArray
is my array
But it always dies and doesn’t show any index on screen.
Can anyone help me?
3
Answers
I got it working using this code
This way I don't need to find the index first.
Credits to @Cositanto
you can try this :
Regards,
Try in this way:
Output: