lundi 2 janvier 2023

I'm trying to merge a multidimensional array and iteratively reindex the results into a new array for get random result

I'm a bit new to PHP and I try hard but I can't merge this array into one in order to reindex it then apply the array_rand function to get a random result, I've done a lot of research and done some many tests but nothing works.

Someone can help me ?

Here's my code:

$mls = array_map(function ($ar) {return $ar['source_url'];}, $img);

        foreach ($mls as $vle) {
            $cnt = basename($vle, '.jpg');
            $exp = explode('-', $cnt);

            foreach ($nsm as $ats) {

                $arr = "/$ats/i";
            
                $res = preg_grep($arr, $exp);
                

                if($res){
                    
                    $sdb = implode(' ', $res);

                    $pol = explode(' ',$sdb); 

                    echo '<pre>';
                    var_dump($pol);
                    echo '</pre>';
                }
            }
            
        }

And result

    array(1) {
  [0]=>
  string(12) "pressedujour"
}

array(1) {
  [0]=>
  string(12) "pressedujour"
}

array(1) {
  [0]=>
  string(12) "pressedujour"
}

array(1) {
  [0]=>
  string(12) "pressedujour"
}

array(1) {
  [0]=>
  string(15) "internationales"
}

array(1) {
  [0]=>
  string(12) "pressedujour"
}

array(1) {
  [0]=>
  string(12) "pressedujour"
}



Aucun commentaire:

Enregistrer un commentaire