Jump to content


Photo

popular array


  • Please log in to reply
1 reply to this topic

#1 redarrow

redarrow
  • Members
  • PipPipPip
  • Advanced Member
  • 7,308 posts
  • Locationlondon

Posted 24 March 2006 - 09:31 PM


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

The arrays i am learning and lernt



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";
?>

Wish i new all about php DAM i will have to learn
((EMAIL CODE THAT WORKS))
http://simpleforum.ath.cx/mail2.inc
((PAYPAL INTEGRATION THAT WORKS))
http://simpleforum.a...aypal1_info.inc

#2 SiC_Goat

SiC_Goat
  • Members
  • PipPip
  • Member
  • 19 posts
  • LocationNew York

Posted 25 March 2006 - 06:25 AM

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;
}
I am Orca!! A very powerful whale!!!




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users