There are way to do this in JavaScript, but in PHP they don't seem to work:
$myArray = array(
array(
"name" => "John Doe",
"occupation" => "streamer"
),
array(
"name" => "Jena Doe",
"occupation" => "delivery services"
)
);
$newItem = array(
"name" => "John Doe",
"occupation" => "delivery services"
);
// now check if the name already exists
// to prevent from adding a duplicate clone of John Doe
if (!array_map(function($i){ if ($i['name'] === $newItem['name']) return true; else return false; }, $myArray)) {
$myArray[] = $newItem;
}
Why am I getting Undefined variable: $newItem
and how can I do this?