Code: Select all
$array = array('test1' => 'test1_value', 'test2' => 'test2_value', 'test3' => 'test3_value');
for($i=0;$i<count($array);$i++)
{
echo $array[$i] . "<br />";
}Moderator: General Moderators
Code: Select all
$array = array('test1' => 'test1_value', 'test2' => 'test2_value', 'test3' => 'test3_value');
for($i=0;$i<count($array);$i++)
{
echo $array[$i] . "<br />";
}Code: Select all
$array = array('test1' => 'test1_value', 'test2' => 'test2_value', 'test3' => 'test3_value');
foreach ($array as $name=>$value)
{
echo $value . "<br />";
}
Code: Select all
main_key =>key1 => value,
key2 => value,
key3 => key3.1 => value,
key3.2 => value
key4 => key4.1 => valueThat's because it returns an array where both the numerical and associative keys are set. The array has everything twice.gadonj wrote:but I find that odd as you can use mysql_fetch_array to get an array that is both.
Code: Select all
$array = array('test1' => 'test1_value', 'test2' => 'test2_value', 'test3' => 'test3_value');
$keys = array_keys($array); $count = count($keys);
for ($i = 0; $i < $count; $i++) {
echo $i, " => ", $keys[$i], " => ", $array[$keys[$i]], "\n";
}