I need to search value in array and get its index but as per my code its giving wrong result. I am explaining my code below.
$arr = [{
"attribute_code":"cake_flavour",
"value":"192"
},
{
"attribute_code":"cake_weight",
"value":"232"
}]
$p ='Cake flavour';
$atcodeindex = array_search(preg_replace('/[^a-z]/', "", strtolower($p)), preg_replace('/[^a-z]/', "", strtolower(array_column($arr, 'attribute_code'))));
echo $atcodeindex;
Here I am not getting the index at all. I need to check if value of $p
is matching with that array if present the index should be fetched. here the expected output should be 0.