Skip to content

Instantly share code, notes, and snippets.

<?php
/*
https://leetcode.com/problems/two-sum/submissions/
Given an array of integers, return indices of the two numbers such that they add up to a specific target.
You may assume that each input would have exactly one solution, and you may not use the same element twice.
Example:
const arr = [
"apple",
[
"banana",
"strawberry",
"apple",
["banana", "strawberry", "apple", ["banana", "strawberry", "apple"]]
]
];
<?php
function arrayFlat(array $array): array
{
return array_reduce($array, function ($acc, $item) {
return array_merge($acc, is_array($item) ? arrayFlat($item) : [$item]);
}, []);
}
function countItems(array $arr, string $item): int
{