Jump to content

popular array


redarrow

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]
Link to comment
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;
}
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

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.