willyamPax Posted July 24, 2008 Share Posted July 24, 2008 can u use an array without an index? and its empty and u use it without index in your loop... can anyone help me... im such a newbie... Quote Link to comment Share on other sites More sharing options...
sader Posted July 24, 2008 Share Posted July 24, 2008 look at foreach Quote Link to comment Share on other sites More sharing options...
natbob Posted July 24, 2008 Share Posted July 24, 2008 I think you may be meaning somthing like this: <?php $myArray = array(); $myArray[] = 'array item 0'; $myArray[] = 'Array item 1'; echo $myArray[0]; //echos array item 0 ?> If you wanted preform a specific action to each item: <?php $myArray = array('me', 'myself', 'and', 'I'); foreach ($myArray as $arrayItem) { echo "$arrayItem <br>"; } //This would output me<br>myself<br>and<br>I<br> ?> Quote Link to comment Share on other sites More sharing options...
willyamPax Posted July 24, 2008 Author Share Posted July 24, 2008 <?php $returnArray= array(); $myArray = array('me', 'myself', 'and', 'I'); for ($i=0;$i<4;$i++) { $returnArray[]=$myArray[$i]; //just like this....the returnArray has no index echo $returnArray[].'<br />'; } //sorry for not giving an example so here it is ?> meaning u wont put an index to your return array coz my classmates keeps on insisting that its possible...thats why im confuse?? ??? Quote Link to comment Share on other sites More sharing options...
teng84 Posted July 24, 2008 Share Posted July 24, 2008 if you dont put an index default is 0,1,2,3 n.... eg ,,, $array = array(1,2,3,4); now your array index will be echo $array[0]; //1 echo $array[1]; //2 echo $array[2]; //3 Quote Link to comment Share on other sites More sharing options...
cooldude832 Posted July 24, 2008 Share Posted July 24, 2008 To answer your question seriously no. replacing your word "index" with php's term of key you can not define an array without having keys that have values under the scope of a single variable PHP is actually an ordered map. A map is a type that associates values to keys. This type is optimized for several different uses; it can be treated as an array, list (vector), hash table (an implementation of a map), dictionary, collection, stack, queue, and probably more. As array values can be other arrays, trees and multidimensional arrays are also possible. using the syntax of <?php $var = arrary(); $var[] = "fish"; $var[] = "cat'; ?> Is still technically assigning keys (using a concept similar to mysql's AUTO_INCREMENT parameters on primary keys) Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.