nelle note..
Codice PHP:
<?php
function SearchBiDimArray(&$theArray, $dimNo, $searchValue, $returnIndex = true){
if(is_array($theArray)){
$keys = array_keys($theArray[0]);
$key = $keys[$dimNo];
$elcount = count($theArray);
for($i=0; $i < $elcount; $i++){
if($theArray[$i][$key] === $searchValue){
if ($returnIndex){
return $i;
}
else{
return $theArray[$i];
}
}
}
}
else{
return array_search($searchValue, $theArray);
}
}
$theArray = array();
$theArray[0]['firstproperty'] = 'avalue1';
$theArray[0]['secondproperty'] = 'anothervalue1';
$theArray[1]['firstproperty'] = 'avalue2';
$theArray[1]['secondproperty'] = 'anothervalue2';
$theArray[2]['firstproperty'] = 'avalue3';
$theArray[2]['secondproperty'] = 'anothervalue3';
print SearchBiDimArray($theArray, 1, 'anothervalue2', true);
// result is 1
print SearchBiDimArray($theArray, 1, 'anothervalue2', true);
// result is
//Array
//(
// [firstproperty] => avalue2
// [secondproperty] => anothervalue2
//)
?>