visitor (0 QPoints)
  • FR
  • EN
  • NL
  • DE
  • ES
315 experts, 1193 registered users, 1659 questions already answered
European Experts Exchange, the very best site for high-quality IT solutions

New Improved Search!

 


05/10/2011 1h30 : Steve Jobs is dead, the father of Apple ][ is gone, we are all orphaned.

Languages :: PHP :: Arrays in PHP


By: PHP newbee U.S.A.  Date: 19/06/2003 00:00:00  English  Points: 20 Status: Answered
Quality : Excellent
Thanx for the previos help, all of your for newline question.

I have a question regarding arrays

can i add elements to an array like

array[];
i=0;//at start
some loop
{
array=$string
i++;
}

The content of the variable $string keeps on changing and i want to store the values of that variable sequentially.
By: keynine Date: 19/06/2003 20:13:00 English  Type : Comment
it is better in this way:

some loop {
array[] = $string;
}

the array variable will expand its array size in every loop with its index incrimented.


By: VGR Date: 19/06/2003 20:44:00 English  Type : Answer
no, it's not "better", it's different. And it's not very practical if you need to add other data in the same array element and you can't affect it to array(the values) ;-)

In that case, you need the index. By the way, both produce exactly the same array finally, so...

yes, that's good :

$thearray=array(); // emptied
$i=0;//at start
some loop {
$thearray[$i]=$string;
$i++;
} // loop

Do register to be able to answer

EContact
browser fav
page generated in 333.361150 milliseconds

Why Google AdSense ads ?

compteur
 Ranking-Hits PageRank for this page