<?php

namespace Helpers\Outil;

class InMultiArray
{
    
    public function __construct()
    {
    }

    /**
     * Fonction permettant de verifie l'existence d'une valeur dans un tableau a multi-dimension
     * @param string $value
     * @param array<mixed> $array
     * @return boolean
     */
    // phpcs:ignore
    public static function in_multi_array($value, $array)
    {
        foreach ($array as $key => $item) {
            // Item is not an array
            if (!is_array($item)) {
                // Is this item our value?
                if ($item == $value) {
                    return true;
                }
            } else {
                // Item is an array
                // See if the array name matches our value
                //if ($key == $value) return true;
                $multiArray = new InMultiArray();
                // See if this array matches our value
                if (in_array($value, $item)) {
                    return true;
                } elseif ($multiArray->in_multi_array($value, $item)) {
                    // Search this array
                    return true;
                }
            }
        }
        
        // Couldn't find the value in array
        return false;
    }
}
