Jump to content
SaranacLake

Create array with offset?

Recommended Posts

First off, what are the names for the types of arrays?

What do you call an array that uses integers for the key?

I think when the key is text it is called an associative array?

Anyways...

 

Is there a way to create an array where they keys are integers, but you are defining the first entry?

I would like my array to either start with a "1" or maybe "1001".

How do I do that?

 

Share this post


Link to post
Share on other sites
22 minutes ago, SaranacLake said:

First off, what are the names for the types of arrays?

In PHP, it's basically either associative or not.

22 minutes ago, SaranacLake said:

What do you call an array that uses integers for the key?

An array. Sometimes "list".

22 minutes ago, SaranacLake said:

I think when the key is text it is called an associative array?

Not just string. Associative is when the keys have some sort of particular meaning. You could have an associative array for weekday names. You could also have a non-associative ("list") array for weekday names. And they could even be the same thing. What matters is how the array is used.

22 minutes ago, SaranacLake said:

Is there a way to create an array where they keys are integers, but you are defining the first entry?

Yes: by creating an array where you define the first entry.

Share this post


Link to post
Share on other sites
8 minutes ago, requinix said:

 

Yes: by creating an array where you define the first entry.

But I'm not sure of how to do that,

I create my array in a llop...

	while(($file = readdir($handle)) != FALSE){
	     $photoFiles[] = $file;
	}
	

 

If I was doing this out of a loop I guess my first entry could be...

$photoFiles[1001] = something;

 

But how do I do that in the loop and not have everything be $photoFiles[1001] ?

 

Share this post


Link to post
Share on other sites

You can use a variable there: $photoFiles[$i] = $file; That variable $i can be initialised and incremented.

Edited by chhorn

Share this post


Link to post
Share on other sites

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.