<?php
/**
 * Created Vladimir Guerra
 * User: vlade
 * Date: 9/10/14
 * Time: 1:59 PM
 */

namespace VGM\WOBundle\Utils;

class Jobeet
{
    static public function slugify($text)
    {
        // replace all non letters or digits by -
        $text = preg_replace('/\W+/', '-', $text);

        // trim and lowercase
        $text = strtolower(trim($text, '-'));

        return $text;
    }

    public function my_array_search($value, $array, $key, $level = 0){
        $results = array();

        if (is_array($array)){
            if($level == 0){
                if (isset($array[$key]) && $array[$key] == $value)
                    $results[] = $array;
            }

            foreach($array as $sub_array){
                $results = array_merge($results, my_array_search($value, $sub_array, $key, $level - 1));
            }
        }

        return $results;
    }
}

class MyUtils
{
    public function my_array_search($value, $array, $key, $level = 0){
        $results = array();

        if (is_array($array)){
            if($level == 0){
                if (isset($array[$key]) && $array[$key] == $value)
                    $results[] = $array;
            }

            foreach($array as $sub_array){
                $results = array_merge($results, my_array_search($value, $sub_array, $key, $level - 1));
            }
        }

        return $results;
    }
}