[FX.php List] Getting "-recid" for 1 record

DC dan.cynosure at dbmscan.com
Wed Jul 19 14:18:51 MDT 2006


I didn't really like the fact that what I put together yesterday  
resulted in nested arrays. so, i took another crack at splitting  
recids and modcounts into their own tidy little associative array  
(without using a foreach to iterate over the arrays - unless you are  
in PHP4). here's what I came up with:

<?php
// show another way how to get an assoc array from FX.php data
// with rec id as key and mod count as value

// dummy data similar to FX.php array
$ResultAll['data'] = array('1000.11'=>1,'2000.22'=>2);

// get the keys which are the in the format recid.modcount
$keys_array = array_keys($ResultAll['data']);
// convert to string
$keys_as_string = implode(' ',$keys_array);
// split recids into array
$recids_array = preg_split("/\.[0-9]+\s?/", $keys_as_string, -1,  
PREG_SPLIT_NO_EMPTY);
// split modcounts into array
$modcounts_array = preg_split("/[0-9]+\./", $keys_as_string, -1,  
PREG_SPLIT_NO_EMPTY);
// combine using PHP5 function (need function below if you are in PHP4)
$array = array_combine($recids_array, $modcounts_array);

// show the array
echo '<pre>';
print_r($array);
echo '</pre>';

//---------------------------
// fall back for php4 people who don't have
// the useful new array_combine function
function array_combine ($arr_keys, $arr_vals) {
	foreach($arr_keys as $key => $val) {$arr_r[$val] = $arr_vals[$key];}
	return $arr_r;
}
?>

archived at: http://dbmscan.com/snippets/ in the FX helpers section.

again, enjoy.

dan



More information about the FX.php_List mailing list