Function to Create an Array from Database Results in PHP

This simple function will create an array out of the multi-dimensional rows returned from a database query.

function mysql_fetch_array_r($result,$result_type=MYSQL_NUM) {
	$arr = array();
	for($i=0;$i<@mysql_num_rows($result);$i++)  {
		array_push($arr,@mysql_fetch_array($result,$result_type));
	}
	return $arr[0]; // on error, $arr is empty
}

Leave a Reply