Jump to content

can u use an array without an index?


willyamPax

Recommended Posts

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

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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)

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.