Solution 1 simple

 echo "id: " .$id ."<br>"; //test
  echo "vecteur: " .$vecteuR ."<br>"; //test
$vecteuR=explode(";",$vecteuR);
  echo "vecteur: " .print_r($vecteuR) ."<br>"; //test
  $cherche=array_search($id,$vecteuR);
  echo "cherchepos: " .$cherche ."<br>"; //test
  echo "actual value: " .$vecteuR[$cherche]."<br>"; //test
  $prev=$cherche-1;
  $next=$cherche+1;
  echo "prev value: " .$vecteuR[$prev]."<br>"; //test
  echo "next value: " .$vecteuR[$next]."<br>"; //test

Solution 2 compliqué

<?php 
//This Is a Function For Seraching For a Value In an Array.

//Add Values To Array
$map[0] = array(Name => "Ranga" , Age => "20");
$map[1]= array(Name => "Ravi", Age => "30");
$map[2]=  array(Name => "Kanc", Age => "20");

$val = "20";  //Value we Are Going To Search For
// Calling Function 
search($map, $val);

//Function
function search($map, $val)
{
   $count = 0 ;
foreach($map as $key => $row)
{
 
  foreach($row as  $key1 => $cellvalue)
  {
     
      if($cellvalue == $val)
      {
      print $count . "----->" . $row[Name];
      $count = $count + 1;
      echo "<br/>";
       
      }
       
  }
   
} 
 
}

?> 
 
info/array-search.txt · Dernière modification: 2011/06/07 10:16 (modification externe)
 
Recent changes RSS feed Creative Commons License Donate Powered by PHP Valid XHTML 1.0 Valid CSS Driven by DokuWiki