In Action

Php Toycode - Convert a Hash to an Array

Simple example to convert a hash to an array.

Php in Action


forloop



Toycode

Php Code

Just cut-n-paste to reuse.

     
<?php
//hash storing an array
$aarr["1993-03-02"] = '';
$aarr["1992-11-30"] = '';
$aarr["1996-12-01"] = ''; 
$aarr["1992-01-22"] = '';
$aarr["1992-12-14"] = '';
$aarr["1993-03-11"] = '';

$iarr=array();

//loop through assoc array
foreach( $aarr as $key => $value)
{
	echo "$key";
	echo " => $value";
	echo "<br \>";
	array_push($iarr,$key);
}

$sz = sizeof($iarr);
echo "size of array is " . $sz . "<br />";
rsort($iarr);

for ($i=0;$i<$sz;$i++)
{
	echo $iarr[$i] . "<br />";
}	

?>