Jump to content

Archived

This topic is now archived and is closed to further replies.

redarrow

popular array

Recommended Posts


What is the main array i need to know best thank you.

The arrays i am learning and lernt


[code]

example 1
<?

$lucky=array("food","dog","home","foot","pool","leg","body","head","teth","ear");  
for($i=0; $i<count($lucky); $i++){
echo "<br>$lucky[$i]<br>normal array";
}

?>


<?
example 2

$lucky=array("food"=>"dog","home"=>"foot","pool"=>"leg","body"=>"head","teth"=>"ear");  

while(list($i, $j,)=each($lucky)){
echo "<br>".$i."<br>".$j."<br>assotate array";
}

?>




<?
example 3

$lucky=array("dog","home","foot","pool","leg","body","head","teth","ear");  

foreach( $lucky as $i => $j){

echo "<br>".$i."<br>".$j."<br>forech array";

}
?>


<?
example 4

$lucky=array(array("food","dog","home","foot","pool","leg","body","head","teth","ear"),
             array("food","dog","home","foot","pool","leg","body","head","teth","ear"));  
echo"<br><br> ".$lucky[1][0]."<br>double array";
?>

<?
example 5

$lucky=array("myarray1"=>array("food","dog","home","foot","pool","leg","body","head","teth
","ear"),
"myarray2"=>array("food"=>"a","home"=>"b","pool"=>"c","leg"=>"d","teth"=>"e")
);  
echo"<br><br>".$lucky[myarray1][1]."<br>double array named";
?>
[/code]

Share this post


Link to post
Share on other sites
If the array will have string indexes this is pretty common

$array = array(
"index1" => 1,
"index2" => new Object(),
"index3" => "string");

If the array will use integer indexes and they are asigned at once

$array = array("field1", "field2", "field3");

If the array is added to via iteration

for($i=0;$i<$value;$i++)
{
$array[$i] = $someSource;
}

Share this post


Link to post
Share on other sites

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.